@@ -5,39 +5,35 @@ describe('type assertions', () => {
55 const chainableElement = $ ( 'findMe' )
66 const chainableArray = $$ ( 'ul>li' )
77
8+ // Type assertions
9+ let expectPromiseVoid : Promise < void >
10+ let expectVoid : void
11+
812 describe ( 'Browser' , ( ) => {
913 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
1414
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
1823
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' )
2224 // @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' ) )
2430 } )
2531
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
2834 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-
3935 // @ts -expect-error
40- const expectVoid2 : void = expect ( browser ) . toHaveUrl ( expect . stringContaining ( 'WebdriverIO' ) )
36+ await expect ( element ) . not . toHaveUrl ( 'https://example.com' )
4137 } )
4238 } )
4339 } )
@@ -78,6 +74,25 @@ describe('type assertions', () => {
7874 } )
7975 } )
8076
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+
8196 describe ( 'toMatchSnapshot' , ( ) => {
8297
8398 it ( 'should not have ts errors when typing to Promise<void> for an element' , async ( ) => {
0 commit comments