1
1
import * as React from 'react' ;
2
- import { useBool , useComponentId } from './hooks' ;
2
+ import { useBool } from './hooks' ;
3
3
4
4
import { render } from '@testing-library/react' ;
5
- import { act } from 'react-dom/test-utils' ;
6
5
7
6
describe ( 'useBool' , ( ) => {
8
7
it ( 'should use initial value creator function' , async ( ) => {
@@ -31,13 +30,13 @@ describe('useBool', () => {
31
30
} ;
32
31
33
32
render ( < HookComponent /> ) ;
34
- act ( ( ) => {
33
+ React . act ( ( ) => {
35
34
toggle ( ) ;
36
35
} ) ;
37
36
38
37
expect ( value ! ) . toBe ( false ) ;
39
38
40
- act ( ( ) => {
39
+ React . act ( ( ) => {
41
40
toggle ( ) ;
42
41
} ) ;
43
42
expect ( value ! ) . toBe ( true ) ;
@@ -53,45 +52,15 @@ describe('useBool', () => {
53
52
} ;
54
53
55
54
render ( < HookComponent /> ) ;
56
- act ( ( ) => {
55
+ React . act ( ( ) => {
57
56
setValue ( false ) ;
58
57
} ) ;
59
58
60
59
expect ( value ! ) . toBe ( false ) ;
61
60
62
- act ( ( ) => {
61
+ React . act ( ( ) => {
63
62
setValue ( true ) ;
64
63
} ) ;
65
64
expect ( value ! ) . toBe ( true ) ;
66
65
} ) ;
67
66
} ) ;
68
-
69
- describe ( 'useComponentId' , ( ) => {
70
- let id1 = '' ;
71
- let id1AfterFirstRender = '' ;
72
-
73
- let id2 = '' ;
74
- let id2AfterFirstRender = '' ;
75
-
76
- const HookComponent1 = ( { text } : { text : string } ) => {
77
- id1 = useComponentId ( ) ;
78
- return < div > { text } </ div > ;
79
- } ;
80
-
81
- const HookComponent2 = ( { text } : { text : string } ) => {
82
- id2 = useComponentId ( ) ;
83
- return < div > { text } </ div > ;
84
- } ;
85
-
86
- const { rerender : rerender1 } = render ( < HookComponent1 text = { 'component1' } /> ) ;
87
- id1AfterFirstRender = id1 ;
88
- rerender1 ( < HookComponent1 text = { 'component1 second render' } /> ) ;
89
-
90
- const { rerender : rerender2 } = render ( < HookComponent2 text = { 'component2' } /> ) ;
91
- id2AfterFirstRender = id2 ;
92
- rerender2 ( < HookComponent2 text = { 'component2 second render' } /> ) ;
93
-
94
- expect ( id1 ) . toBe ( id1AfterFirstRender ) ;
95
- expect ( id2 ) . toBe ( id2AfterFirstRender ) ;
96
- expect ( id1 ) . not . toBe ( id2 ) ;
97
- } ) ;
0 commit comments