@@ -5,38 +5,40 @@ describe('type assertions', () => {
5
5
const chainableElement = $ ( 'findMe' )
6
6
const chainableArray = $$ ( 'ul>li' )
7
7
8
- describe ( 'toHaveUrl ' , ( ) => {
8
+ describe ( 'Browser ' , ( ) => {
9
9
const browser : WebdriverIO . Browser = { } as unknown as WebdriverIO . Browser
10
- it ( 'should not have ts errors and be able to await the promise when actual is browser' , async ( ) => {
11
- const expectPromiseVoid : Promise < void > = expect ( browser ) . toHaveUrl ( 'https://example.com' )
12
- await expectPromiseVoid
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
13
14
14
- const expectNotPromiseVoid : Promise < void > = expect ( browser ) . not . toHaveUrl ( 'https://example.com' )
15
- await expectNotPromiseVoid
16
- } )
15
+ const expectNotPromiseVoid : Promise < void > = expect ( browser ) . not . toHaveUrl ( 'https://example.com' )
16
+ await expectNotPromiseVoid
17
+ } )
17
18
18
- it ( 'should have ts errors and not need to await the promise when actual is browser' , async ( ) => {
19
+ it ( 'should have ts errors and not need to await the promise when actual is browser' , async ( ) => {
19
20
// @ts -expect-error
20
- const expectVoid : void = expect ( browser ) . toHaveUrl ( 'https://example.com' )
21
- // @ts -expect-error
22
- const expectNotVoid : void = expect ( browser ) . not . toHaveUrl ( 'https://example.com' )
23
- } )
21
+ const expectVoid : void = expect ( browser ) . toHaveUrl ( 'https://example.com' )
22
+ // @ts -expect-error
23
+ const expectNotVoid : void = expect ( browser ) . not . toHaveUrl ( 'https://example.com' )
24
+ } )
24
25
25
- it ( 'should have ts errors when actual is an element' , async ( ) => {
26
+ it ( 'should have ts errors when actual is an element' , async ( ) => {
26
27
// @ts -expect-error
27
- await expect ( element ) . toHaveUrl ( 'https://example.com' )
28
- } )
28
+ await expect ( element ) . toHaveUrl ( 'https://example.com' )
29
+ } )
29
30
30
- it ( 'should have ts errors when actual is an ChainableElement' , async ( ) => {
31
+ it ( 'should have ts errors when actual is an ChainableElement' , async ( ) => {
31
32
// @ts -expect-error
32
- await expect ( chainableElement ) . toHaveUrl ( 'https://example.com' )
33
- } )
33
+ await expect ( chainableElement ) . toHaveUrl ( 'https://example.com' )
34
+ } )
34
35
35
- it ( 'should support stringContaining' , async ( ) => {
36
- const expectVoid1 : Promise < void > = expect ( browser ) . toHaveUrl ( expect . stringContaining ( 'WebdriverIO' ) )
36
+ it ( 'should support stringContaining' , async ( ) => {
37
+ const expectVoid1 : Promise < void > = expect ( browser ) . toHaveUrl ( expect . stringContaining ( 'WebdriverIO' ) )
37
38
38
- // @ts -expect-error
39
- const expectVoid2 : void = expect ( browser ) . toHaveUrl ( expect . stringContaining ( 'WebdriverIO' ) )
39
+ // @ts -expect-error
40
+ const expectVoid2 : void = expect ( browser ) . toHaveUrl ( expect . stringContaining ( 'WebdriverIO' ) )
41
+ } )
40
42
} )
41
43
} )
42
44
@@ -227,7 +229,11 @@ describe('type assertions', () => {
227
229
const expectPromise2 : Promise < void > = expect ( promiseNetworkMock ) . toBeRequestedTimes ( 2 ) // await expect(mock).toBeRequestedTimes({ eq: 2 })
228
230
const expectPromise3 : Promise < void > = expect ( promiseNetworkMock ) . toBeRequestedTimes ( { gte : 5 , lte : 10 } ) // request called at least 5 times but less than 11
229
231
230
- const expectPromise4 : Promise < void > = expect ( promiseNetworkMock ) . toBeRequestedWith ( {
232
+ const expectPromise4 : Promise < void > = expect ( promiseNetworkMock ) . not . toBeRequested ( )
233
+ const expectPromise5 : Promise < void > = expect ( promiseNetworkMock ) . not . toBeRequestedTimes ( 2 ) // await expect(mock).toBeRequestedTimes({ eq: 2 })
234
+ const expectPromise6 : Promise < void > = expect ( promiseNetworkMock ) . not . toBeRequestedTimes ( { gte : 5 , lte : 10 } ) // request called at least 5 times but less than 11
235
+
236
+ const expectPromise7 : Promise < void > = expect ( promiseNetworkMock ) . toBeRequestedWith ( {
231
237
url : 'http://localhost:8080/api/todo' , // [optional] string | function | custom matcher
232
238
method : 'POST' , // [optional] string | array
233
239
statusCode : 200 , // [optional] number | array
@@ -236,6 +242,10 @@ describe('type assertions', () => {
236
242
postData : { title : 'foo' , description : 'bar' } , // [optional] object | function | custom matcher
237
243
response : { success : true } , // [optional] object | function | custom matcher
238
244
} )
245
+
246
+ const expectPromise8 : Promise < void > = expect ( promiseNetworkMock ) . toBeRequestedWith ( expect . objectContaining ( {
247
+ response : { success : true } , // [optional] object | function | custom matcher
248
+ } ) )
239
249
} )
240
250
241
251
it ( 'should have ts errors when typing to void' , async ( ) => {
@@ -247,7 +257,14 @@ describe('type assertions', () => {
247
257
const expectPromise3 : void = expect ( promiseNetworkMock ) . toBeRequestedTimes ( { gte : 5 , lte : 10 } ) // request called at least 5 times but less than 11
248
258
249
259
// @ts -expect-error
250
- const expectPromise4 : void = expect ( promiseNetworkMock ) . toBeRequestedWith ( {
260
+ const expectPromise4 : void = expect ( promiseNetworkMock ) . not . toBeRequested ( )
261
+ // @ts -expect-error
262
+ const expectPromise5 : void = expect ( promiseNetworkMock ) . not . toBeRequestedTimes ( 2 ) // await expect(mock).toBeRequestedTimes({ eq: 2 })
263
+ // @ts -expect-error
264
+ const expectPromise6 : void = expect ( promiseNetworkMock ) . not . toBeRequestedTimes ( { gte : 5 , lte : 10 } ) // request called at least 5 times but less than 11
265
+
266
+ // @ts -expect-error
267
+ const expectPromise7 : void = expect ( promiseNetworkMock ) . toBeRequestedWith ( {
251
268
url : 'http://localhost:8080/api/todo' , // [optional] string | function | custom matcher
252
269
method : 'POST' , // [optional] string | array
253
270
statusCode : 200 , // [optional] number | array
@@ -256,6 +273,11 @@ describe('type assertions', () => {
256
273
postData : { title : 'foo' , description : 'bar' } , // [optional] object | function | custom matcher
257
274
response : { success : true } , // [optional] object | function | custom matcher
258
275
} )
276
+
277
+ // @ts -expect-error
278
+ const expectPromise8 : void = expect ( promiseNetworkMock ) . toBeRequestedWith ( expect . objectContaining ( {
279
+ response : { success : true } , // [optional] object | function | custom matcher
280
+ } ) )
259
281
} )
260
282
} )
261
283
@@ -292,15 +314,15 @@ describe('type assertions', () => {
292
314
293
315
it ( 'should have ts error when using await and actual is non-promise type' , async ( ) => {
294
316
// @ts -expect-error
295
- const expectWdioMatcher : WdioMatchers < Promise < void > , string > = expect . soft ( expectString )
317
+ const expectWdioMatcher : jest . MatcherAndInverse < Promise < void > , string > = expect . soft ( expectString )
296
318
297
319
// @ts -expect-error
298
320
const expectVoid : Promise < void > = expect . soft ( expectString ) . toBe ( 'Test Page' )
299
321
} )
300
322
301
323
it ( 'should not have ts error and need to be awaited/be a promise if actual is a promise type' , async ( ) => {
302
- // @ts -expect-error
303
- const expectWdioMatcher : WdioMatchers < void , Promise < string > > = expect . soft ( expectPromise )
324
+ // @ts -expect-error
325
+ const expectWdioMatcher : jest . MatcherAndInverse < void , Promise < string > > = expect . soft ( expectPromise )
304
326
// @ts -expect-error
305
327
const expectVoid : void = expect . soft ( expectPromise ) . toBe ( 'Test Page' )
306
328
} )
0 commit comments