mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
Add useToggle tests
This commit is contained in:
parent
76640295d5
commit
3bd1cbcf9d
49
src/__tests__/useToggle.test.tsx
Normal file
49
src/__tests__/useToggle.test.tsx
Normal file
@ -0,0 +1,49 @@
|
||||
import { act, cleanup, renderHook } from 'react-hooks-testing-library';
|
||||
import useToggle from '../useToggle';
|
||||
|
||||
afterEach(cleanup);
|
||||
|
||||
describe('useToggle', () => {
|
||||
it('should be defined', () => {
|
||||
expect(useToggle).toBeDefined();
|
||||
});
|
||||
|
||||
const hook = renderHook(props => useToggle(props), { initialProps: false });
|
||||
|
||||
it('should return initial state on initial render', () => {
|
||||
expect(hook.result.current[0]).toBe(false);
|
||||
});
|
||||
|
||||
it('should update state with correct value', () => {
|
||||
hook.rerender(true);
|
||||
expect(hook.result.current[0]).toBe(true);
|
||||
|
||||
act(() => {
|
||||
hook.result.current[1](false);
|
||||
});
|
||||
|
||||
expect(hook.result.current[0]).toBe(false);
|
||||
});
|
||||
|
||||
// it('should toggle state without a value parameter', () => {
|
||||
// act(() => {
|
||||
// hook.result.current[1]();
|
||||
// });
|
||||
|
||||
// expect(hook.result.current[0]).toBe(true);
|
||||
// });
|
||||
|
||||
// it('should ignore non-boolean parameters', () => {
|
||||
// act(() => {
|
||||
// hook.result.current[1]('string');
|
||||
// });
|
||||
|
||||
// expect(hook.result.current[0]).toBe(true);
|
||||
|
||||
// act(() => {
|
||||
// hook.result.current[1]({});
|
||||
// });
|
||||
|
||||
// expect(hook.result.current[0]).toBe(false);
|
||||
// });
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user