File tree Expand file tree Collapse file tree 3 files changed +34
-2
lines changed Expand file tree Collapse file tree 3 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -5,5 +5,4 @@ docs/build
55docs /src /hooks
66docs /blog
77dist
8- example
9- test
8+ example
Original file line number Diff line number Diff line change 5454 ],
5555 "devDependencies" : {
5656 "@size-limit/preset-small-lib" : " ^7.0.8" ,
57+ "@testing-library/jest-dom" : " ^5.16.2" ,
58+ "@testing-library/react-hooks" : " ^7.0.2" ,
59+ "@types/jest" : " ^27.4.1" ,
5760 "@types/react" : " ^17.0.39" ,
5861 "@types/react-dom" : " ^17.0.11" ,
5962 "husky" : " ^7.0.4" ,
6063 "react" : " ^17.0.2" ,
6164 "react-dom" : " ^17.0.2" ,
65+ "react-test-renderer" : " ^17.0.2" ,
6266 "size-limit" : " ^7.0.8" ,
6367 "tsdx" : " ^0.14.1" ,
6468 "tslib" : " ^2.3.1" ,
Original file line number Diff line number Diff line change 1+ import { renderHook , act } from '@testing-library/react-hooks' ;
2+ import { useLegacyState } from '../src' ;
3+
4+ const initialState = {
5+ firstName : 'John' ,
6+ } ;
7+
8+ describe ( 'useLegacyState' , ( ) => {
9+ it ( 'should return correct initial state' , ( ) => {
10+ const hook = renderHook ( ( ) => useLegacyState ( initialState ) ) ;
11+ expect ( hook . result . current [ 0 ] ) . toStrictEqual ( initialState ) ;
12+ } ) ;
13+
14+ it ( 'should return the updated state after setState' , ( ) => {
15+ const hook = renderHook ( ( ) => useLegacyState ( initialState ) ) ;
16+ act ( ( ) => hook . result . current [ 1 ] ( { lastName : 'Doe' } ) ) ;
17+ expect ( hook . result . current [ 0 ] ) . toStrictEqual ( {
18+ ...initialState ,
19+ lastName : 'Doe' ,
20+ } ) ;
21+
22+ act ( ( ) => hook . result . current [ 1 ] ( { age : 32 } ) ) ;
23+ expect ( hook . result . current [ 0 ] ) . toStrictEqual ( {
24+ ...initialState ,
25+ lastName : 'Doe' ,
26+ age : 32 ,
27+ } ) ;
28+ } ) ;
29+ } ) ;
You can’t perform that action at this time.
0 commit comments