1
1
mirror of https://github.com/theoludwig/p61-project.git synced 2024-07-17 07:00:12 +02:00
p61-project/presentation/react/hooks/__tests__/useBoolean.test.ts

62 lines
1.6 KiB
TypeScript
Raw Normal View History

2024-02-16 22:51:50 +01:00
import { act, renderHook } from "@testing-library/react-native"
2024-03-16 00:36:44 +01:00
import { useBoolean } from "@/presentation/react/hooks/useBoolean"
2024-02-16 22:51:50 +01:00
describe("hooks/useBoolean", () => {
beforeEach(() => {
jest.clearAllMocks()
})
const initialValues = [true, false]
for (const initialValue of initialValues) {
it(`should set the initial value to ${initialValue}`, () => {
const { result } = renderHook(() => {
return useBoolean({ initialValue })
})
expect(result.current.value).toBe(initialValue)
})
}
it("should by default set the initial value to false", () => {
const { result } = renderHook(() => {
return useBoolean()
})
expect(result.current.value).toBe(false)
})
it("should toggle the value", async () => {
const { result } = renderHook(() => {
return useBoolean({ initialValue: false })
})
await act(() => {
return result.current.toggle()
})
expect(result.current.value).toBe(true)
await act(() => {
return result.current.toggle()
})
expect(result.current.value).toBe(false)
})
it("should set the value to true", async () => {
const { result } = renderHook(() => {
return useBoolean({ initialValue: false })
})
await act(() => {
return result.current.setTrue()
})
expect(result.current.value).toBe(true)
})
it("should set the value to false", async () => {
const { result } = renderHook(() => {
return useBoolean({ initialValue: true })
})
await act(() => {
return result.current.setFalse()
})
expect(result.current.value).toBe(false)
})
})