1
1
import { newTestPage , getHooks , waitForSelector } from "../../test-utils" ;
2
2
import { expect } from "chai" ;
3
3
import { clickNestedText , clickSelector } from "pentf/browser_utils" ;
4
+ import { assertEventually } from "pentf/assert_utils" ;
4
5
5
6
export const description = "Show custom hook name" ;
6
7
@@ -24,47 +25,93 @@ export async function run(config: any) {
24
25
// Callback (Mixed)
25
26
await clickNestedText ( devtools , / C o u n t e r C a l l b a c k $ / ) ;
26
27
await waitForSelector ( devtools , hooksPanel ) ;
27
- expect ( await getHooks ( devtools ) ) . to . deep . equal ( [
28
- [ "useState counterState" , "0" ] ,
29
- [ "useCallback" , "ƒ ()" ] ,
30
- ] ) ;
28
+ await assertEventually (
29
+ async ( ) => {
30
+ expect ( await getHooks ( devtools ) ) . to . deep . equal ( [
31
+ [ "useState counterState" , "0" ] ,
32
+ [ "useCallback" , "ƒ ()" ] ,
33
+ ] ) ;
34
+ } ,
35
+ { crashOnError : false } ,
36
+ ) ;
31
37
32
38
// Reducer
33
39
await clickNestedText ( devtools , / R e d u c e r C o m p o n e n t $ / ) ;
34
40
await waitForSelector ( devtools , hooksPanel ) ;
35
- expect ( await getHooks ( devtools ) ) . to . deep . equal ( [
36
- [ "useReducer customReducer" , '"foo"' ] ,
37
- ] ) ;
41
+ await assertEventually (
42
+ async ( ) => {
43
+ expect ( await getHooks ( devtools ) ) . to . deep . equal ( [
44
+ [ "useReducer customReducer" , '"foo"' ] ,
45
+ ] ) ;
46
+ } ,
47
+ { crashOnError : false } ,
48
+ ) ;
38
49
39
50
// Ref
40
51
await clickNestedText ( devtools , / R e f C o m p o n e n t $ / ) ;
41
52
await waitForSelector ( devtools , hooksPanel ) ;
42
- expect ( await getHooks ( devtools ) ) . to . deep . equal ( [ [ "useRef customRef" , "0" ] ] ) ;
53
+ await assertEventually (
54
+ async ( ) => {
55
+ expect ( await getHooks ( devtools ) ) . to . deep . equal ( [
56
+ [ "useRef customRef" , "0" ] ,
57
+ ] ) ;
58
+ } ,
59
+ { crashOnError : false } ,
60
+ ) ;
43
61
44
62
// useMemo
45
63
await clickNestedText ( devtools , / M e m o C o m p o n e n t $ / ) ;
46
64
await waitForSelector ( devtools , hooksPanel ) ;
47
- expect ( await getHooks ( devtools ) ) . to . deep . equal ( [ [ "useMemo customMemo" , "0" ] ] ) ;
65
+ await assertEventually (
66
+ async ( ) => {
67
+ expect ( await getHooks ( devtools ) ) . to . deep . equal ( [
68
+ [ "useMemo customMemo" , "0" ] ,
69
+ ] ) ;
70
+ } ,
71
+ { crashOnError : false } ,
72
+ ) ;
48
73
49
74
// Multiple (test ordering)
50
75
await clickNestedText ( devtools , / ^ M u l t i p l e $ / ) ;
51
76
await waitForSelector ( devtools , hooksPanel ) ;
52
- expect ( await getHooks ( devtools ) ) . to . deep . equal ( [
53
- [ "useState foo" , "0" ] ,
54
- [ "useState bar" , "0" ] ,
55
- [ "useState baz" , "0" ] ,
56
- ] ) ;
77
+ await assertEventually (
78
+ async ( ) => {
79
+ expect ( await getHooks ( devtools ) ) . to . deep . equal ( [
80
+ [ "useState foo" , "0" ] ,
81
+ [ "useState bar" , "0" ] ,
82
+ [ "useState baz" , "0" ] ,
83
+ ] ) ;
84
+ } ,
85
+ { crashOnError : false } ,
86
+ ) ;
57
87
58
88
// Do nothing for invalid callsites
59
89
await clickNestedText ( devtools , / C a l l b a c k O n l y $ / ) ;
60
90
await waitForSelector ( devtools , hooksPanel ) ;
61
- expect ( await getHooks ( devtools ) ) . to . deep . equal ( [ [ "useCallback" , "ƒ ()" ] ] ) ;
91
+ await assertEventually (
92
+ async ( ) => {
93
+ expect ( await getHooks ( devtools ) ) . to . deep . equal ( [ [ "useCallback" , "ƒ ()" ] ] ) ;
94
+ } ,
95
+ { crashOnError : false } ,
96
+ ) ;
62
97
63
98
await clickNestedText ( devtools , / L a y o u t E f f e c t $ / ) ;
64
99
await waitForSelector ( devtools , hooksPanel ) ;
65
- expect ( await getHooks ( devtools ) ) . to . deep . equal ( [ [ "useLayoutEffect" , "ƒ ()" ] ] ) ;
100
+ await assertEventually (
101
+ async ( ) => {
102
+ expect ( await getHooks ( devtools ) ) . to . deep . equal ( [
103
+ [ "useLayoutEffect" , "ƒ ()" ] ,
104
+ ] ) ;
105
+ } ,
106
+ { crashOnError : false } ,
107
+ ) ;
66
108
67
109
await clickNestedText ( devtools , / ^ E f f e c t $ / ) ;
68
110
await waitForSelector ( devtools , hooksPanel ) ;
69
- expect ( await getHooks ( devtools ) ) . to . deep . equal ( [ [ "useEffect" , "ƒ ()" ] ] ) ;
111
+ await assertEventually (
112
+ async ( ) => {
113
+ expect ( await getHooks ( devtools ) ) . to . deep . equal ( [ [ "useEffect" , "ƒ ()" ] ] ) ;
114
+ } ,
115
+ { crashOnError : false } ,
116
+ ) ;
70
117
}
0 commit comments