@@ -3,7 +3,7 @@ import { JSDOM } from "jsdom";
3
3
import path from "path" ;
4
4
import { promises as fs } from "fs" ;
5
5
import assert from "assert" ;
6
- import { assertAndReturn } from "../support/helpers " ;
6
+ import { findByText } from "@testing-library/dom " ;
7
7
import ICustomWorld from "../support/ICustomWorld" ;
8
8
9
9
Then ( "there should be a HTML report" , async function ( this : ICustomWorld ) {
@@ -21,24 +21,19 @@ Then(
21
21
{ runScripts : "dangerously" }
22
22
) ;
23
23
24
- const dt = assertAndReturn (
25
- Array . from ( dom . window . document . querySelectorAll ( "dt" ) ) . find (
26
- ( el ) => el . textContent === "last run"
27
- ) ,
28
- "Expected to find a 'last run' dt"
24
+ const dt = await findByText (
25
+ dom . window . document . documentElement ,
26
+ "last run" ,
27
+ {
28
+ selector : "dt" ,
29
+ }
29
30
) ;
30
31
31
- const dd = assertAndReturn (
32
- dt . parentElement ?. querySelector ( "dd" ) ,
33
- "Expected to find a 'last run' dt's dd"
34
- ) ;
35
-
36
- const lastRunText = assertAndReturn (
37
- dd . textContent ,
38
- "Expected to find 'XX seconds ago'"
39
- ) ;
32
+ const dd = await findByText ( dt . parentElement ! , / \d + s e c o n d s ? a g o / , {
33
+ selector : "dd" ,
34
+ } ) ;
40
35
41
- assert . match ( lastRunText , / \d + s e c o n d s ? a g o / ) ;
36
+ assert ( dd ) ;
42
37
}
43
38
) ;
44
39
@@ -50,11 +45,12 @@ Then(
50
45
{ runScripts : "dangerously" }
51
46
) ;
52
47
53
- const dt = assertAndReturn (
54
- Array . from ( dom . window . document . querySelectorAll ( "dt" ) ) . find (
55
- ( el ) => el . textContent && / \d + e x e c u t e d / . test ( el . textContent )
56
- ) ,
57
- "Expected to find a 'XX executed' dt"
48
+ const dt = await findByText (
49
+ dom . window . document . documentElement ,
50
+ / \d + e x e c u t e d / ,
51
+ {
52
+ selector : "dt" ,
53
+ }
58
54
) ;
59
55
60
56
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -72,11 +68,12 @@ Then(
72
68
{ runScripts : "dangerously" }
73
69
) ;
74
70
75
- const dd = assertAndReturn (
76
- Array . from ( dom . window . document . querySelectorAll ( "dd" ) ) . find (
77
- ( el ) => el . textContent && / \d + % p a s s e d / . test ( el . textContent )
78
- ) ,
79
- "Expected to find a 'XX% passed' dd"
71
+ const dd = await findByText (
72
+ dom . window . document . documentElement ,
73
+ / \d + % p a s s e d / ,
74
+ {
75
+ selector : "dd" ,
76
+ }
80
77
) ;
81
78
82
79
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -94,19 +91,12 @@ Then(
94
91
{ runScripts : "dangerously" }
95
92
) ;
96
93
97
- const AccordionItemPanel = assertAndReturn (
98
- dom . window . document . querySelector (
99
- '[data-accordion-component="AccordionItemPanel"]'
100
- ) ,
101
- "Expected to find an AccordionItemPanel"
94
+ const AccordionItemPanel = await findByText (
95
+ dom . window . document . documentElement ,
96
+ ( _ , element ) => element ?. textContent ?. includes ( "Attached Image" ) ?? false ,
97
+ { selector : '[data-accordion-component="AccordionItemPanel"]' }
102
98
) ;
103
99
104
- assert . match (
105
- assertAndReturn (
106
- AccordionItemPanel . textContent ,
107
- "Expected AccordionItemPanel to have textContent"
108
- ) ,
109
- / A t t a c h e d I m a g e /
110
- ) ;
100
+ assert ( AccordionItemPanel ) ;
111
101
}
112
102
) ;
0 commit comments