@@ -5,39 +5,35 @@ describe('type assertions', () => {
5
5
const chainableElement = $ ( 'findMe' )
6
6
const chainableArray = $$ ( 'ul>li' )
7
7
8
+ // Type assertions
9
+ let expectPromiseVoid : Promise < void >
10
+ let expectVoid : void
11
+
8
12
describe ( 'Browser' , ( ) => {
9
13
const browser : WebdriverIO . Browser = { } as unknown as WebdriverIO . Browser
10
- describe ( 'toHaveUrl' , ( ) => {
11
- it ( 'should not have ts errors and be able to await the promise when actual is browser' , async ( ) => {
12
- const expectPromiseVoid : Promise < void > = expect ( browser ) . toHaveUrl ( 'https://example.com' )
13
- await expectPromiseVoid
14
14
15
- const expectNotPromiseVoid : Promise < void > = expect ( browser ) . not . toHaveUrl ( 'https://example.com' )
16
- await expectNotPromiseVoid
17
- } )
15
+ describe ( 'toHaveUrl' , ( ) => {
16
+ it ( 'should be supported correctly' , async ( ) => {
17
+ expectPromiseVoid = expect ( browser ) . toHaveUrl ( 'https://example.com' )
18
+ expectPromiseVoid = expect ( browser ) . not . toHaveUrl ( 'https://example.com' )
19
+ expectPromiseVoid = expect ( browser ) . toHaveUrl ( expect . stringContaining ( 'WebdriverIO' ) )
20
+ expectPromiseVoid = expect ( browser ) . toHaveUrl ( expect . any ( String ) )
21
+ expectPromiseVoid = expect ( browser ) . toHaveUrl ( expect . anything ( ) )
22
+ // TODO add more asymmetric matchers
18
23
19
- it ( 'should have ts errors and not need to await the promise when actual is browser' , async ( ) => {
20
- // @ts -expect-error
21
- const expectVoid : void = expect ( browser ) . toHaveUrl ( 'https://example.com' )
22
24
// @ts -expect-error
23
- const expectNotVoid : void = expect ( browser ) . not . toHaveUrl ( 'https://example.com' )
25
+ expectVoid = expect ( browser ) . toHaveUrl ( 'https://example.com' )
26
+ // @ts -expect-error
27
+ expectVoid = expect ( browser ) . not . toHaveUrl ( 'https://example.com' )
28
+ // @ts -expect-error
29
+ expectVoid = expect ( browser ) . toHaveUrl ( expect . stringContaining ( 'WebdriverIO' ) )
24
30
} )
25
31
26
- it ( 'should have ts errors when actual is an element' , async ( ) => {
27
- // @ts -expect-error
32
+ it ( 'should have ts errors when actual is not a Browser element' , async ( ) => {
33
+ // @ts -expect-error
28
34
await expect ( element ) . toHaveUrl ( 'https://example.com' )
29
- } )
30
-
31
- it ( 'should have ts errors when actual is an ChainableElement' , async ( ) => {
32
- // @ts -expect-error
33
- await expect ( chainableElement ) . toHaveUrl ( 'https://example.com' )
34
- } )
35
-
36
- it ( 'should support stringContaining' , async ( ) => {
37
- const expectVoid1 : Promise < void > = expect ( browser ) . toHaveUrl ( expect . stringContaining ( 'WebdriverIO' ) )
38
-
39
35
// @ts -expect-error
40
- const expectVoid2 : void = expect ( browser ) . toHaveUrl ( expect . stringContaining ( 'WebdriverIO' ) )
36
+ await expect ( element ) . not . toHaveUrl ( 'https://example.com' )
41
37
} )
42
38
} )
43
39
} )
@@ -78,6 +74,25 @@ describe('type assertions', () => {
78
74
} )
79
75
} )
80
76
77
+ describe ( 'toHaveText' , ( ) => {
78
+ it ( 'should be supported correctly' , async ( ) => {
79
+ const expectPromise1 : Promise < void > = expect ( element ) . toHaveText ( 'text' )
80
+ const expectPromise2 : Promise < void > = expect ( element ) . toHaveText ( / t e x t / )
81
+ const expectPromise3 : Promise < void > = expect ( element ) . toHaveText ( [ 'text1' , 'text2' ] )
82
+ const expectPromise4 : Promise < void > = expect ( element ) . toHaveText ( [ expect . stringContaining ( 'text1' ) , expect . stringContaining ( 'text2' ) ] )
83
+ const expectPromise5 : Promise < void > = expect ( element ) . toHaveText ( [ / t e x t 1 / , / t e x t 2 / ] )
84
+ const expectPromise6 : Promise < void > = expect ( element ) . toHaveText ( [ 'text1' , / t e x t 1 / , expect . stringContaining ( 'text3' ) ] )
85
+
86
+ const expectPromise7 : Promise < void > = expect ( element ) . not . toHaveText ( 'text' )
87
+
88
+ // @ts -expect-error
89
+ const expectTsError7 : void = expect ( element ) . toHaveText ( 'text' )
90
+
91
+ // @ts -expect-error
92
+ await expect ( browser ) . toHaveText ( 'text' )
93
+ } )
94
+ } )
95
+
81
96
describe ( 'toMatchSnapshot' , ( ) => {
82
97
83
98
it ( 'should not have ts errors when typing to Promise<void> for an element' , async ( ) => {
0 commit comments