diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-10-30 11:18:11 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-11-11 18:15:27 +0100 |
| commit | 84a679b0e48ed76eee2fa44d3caac83591aa3c8c (patch) | |
| tree | 1d418a6c514ff8a04b84ba35c98736e8450f968c /src/utils/hooks/use-boolean/use-boolean.test.ts | |
| parent | 60c49f18389ff625177a57277ef8f292a31097bf (diff) | |
feat(hooks): add useBoolean and useToggle hooks
Diffstat (limited to 'src/utils/hooks/use-boolean/use-boolean.test.ts')
| -rw-r--r-- | src/utils/hooks/use-boolean/use-boolean.test.ts | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/utils/hooks/use-boolean/use-boolean.test.ts b/src/utils/hooks/use-boolean/use-boolean.test.ts new file mode 100644 index 0000000..22d3cdc --- /dev/null +++ b/src/utils/hooks/use-boolean/use-boolean.test.ts @@ -0,0 +1,45 @@ +import { describe, expect, it } from '@jest/globals'; +import { act, renderHook } from '@testing-library/react'; +import { useBoolean } from './use-boolean'; + +describe('use-boolean', () => { + it('returns the initial state', () => { + const initialState = true; + const { result } = renderHook(() => useBoolean(initialState)); + + expect(result.current.state).toBe(initialState); + }); + + it('can set the state to false', () => { + const { result } = renderHook(() => useBoolean()); + + act(() => { + result.current.deactivate(); + }); + + expect(result.current.state).toBe(false); + }); + + it('can set the state to true', () => { + const { result } = renderHook(() => useBoolean()); + + act(() => { + result.current.activate(); + }); + + expect(result.current.state).toBe(true); + }); + + it('can switch the state', () => { + const initialState = true; + const { result } = renderHook(() => useBoolean(initialState)); + + expect(result.current.state).toBe(initialState); + + act(() => { + result.current.toggle(); + }); + + expect(result.current.state).toBe(!initialState); + }); +}); |
