Skip to content

Commit

Permalink
test: add unit test for src/react/utils/useResetAtom.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
gru-bot committed Sep 26, 2024
1 parent 63f98bb commit 1749efa
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/react/utils/useResetAtom.gru.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unused-vars */
import { renderHook } from '@testing-library/react'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { useSetAtom } from '../../react.ts'
import { RESET } from '../../vanilla/utils.ts'
import { useResetAtom } from './useResetAtom.ts'

vi.mock('../../react.ts', async (importOriginal) => {
const actual = await importOriginal<typeof import('../../react.ts')>()
return {
...actual,
useSetAtom: vi.fn(),
}
})

describe('useResetAtom', () => {
const mockSetAtom = vi.fn()

beforeEach(() => {
vi.clearAllMocks()
vi.mocked(useSetAtom).mockReturnValue(mockSetAtom)
})

it('should return a function', () => {
const { result } = renderHook(() => useResetAtom({} as any))
expect(typeof result.current).toBe('function')
})

it('should call setAtom with RESET when invoked', () => {
const { result } = renderHook(() => useResetAtom({} as any))
result.current()
expect(mockSetAtom).toHaveBeenCalledWith(RESET)
})
})

0 comments on commit 1749efa

Please sign in to comment.