-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: useToggle interface changed
- Loading branch information
Showing
4 changed files
with
58 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
// }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters