Skip to content

Commit 294ba96

Browse files
committed
Simplify Jasmine augmentation
1 parent c6304bb commit 294ba96

2 files changed

Lines changed: 5 additions & 20 deletions

File tree

jasmine.d.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
/// <reference types="./types/expect-webdriverio.d.ts"/>
22

3-
/**
4-
* Utility type that wraps non-Promise types in a Promise for Jasmine async matchers.
5-
* If U is already a Promise, PromiseLike, or Chainable, return U as-is.
6-
* Otherwise, wrap U in a Promise<U>.
7-
*/
8-
type EnsurePromise<U extends void | Promise<void>> = U extends Promise<unknown> | PromiseLike<unknown> | WdioPromiseLike<unknown> ? U : Promise<U>
9-
103
declare namespace jasmine {
114

125
/**
136
* Async matchers for Jasmine to allow the typing of `expectAsync` with WebDriverIO matchers.
147
* T is the type of the actual value
15-
* U is the type of the expected value, which will be wrapped in a Promise if it's not already one
8+
* U is the type of the expected value
169
* Both T,U must stay named as they are to override the default `AsyncMatchers` type from Jasmine.
10+
*
11+
* We force Matchers to return a `Promise<void>` since Jasmine's `expectAsync` expects a promise in all cases (different from Jest)
1712
*/
18-
interface AsyncMatchers<T, U extends void | Promise<void>> extends Omit<ExpectWebdriverIO.Matchers<EnsurePromise<U>, T>, 'toMatchSnapshot' | 'toMatchInlineSnapshot'> {
13+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
14+
interface AsyncMatchers<T, U> extends Omit<ExpectWebdriverIO.Matchers<Promise<void>, T>, 'toMatchSnapshot' | 'toMatchInlineSnapshot'> {
1915
/**
2016
* snapshot matcher
2117
* @param label optional snapshot label

test-types/jasmine-async/types-jasmine.test.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -453,13 +453,10 @@ describe('type assertions', () => {
453453

454454
describe('toBe', () => {
455455
it('should expect void type when actual is a boolean', async () => {
456-
// TODO dprevost we migth need to be a Promise here because of the expectAsync of wdio
457456
expectVoid = expect(true).toBe(true)
458457
expectVoid = expect(true).not.toBe(true)
459458

460-
//@ts-expect-error
461459
expectPromiseVoid = expectAsync(true).toBe(true)
462-
//@ts-expect-error
463460
expectPromiseVoid = expectAsync(true).not.toBe(true)
464461
})
465462

@@ -480,9 +477,7 @@ describe('type assertions', () => {
480477
expectPromiseUnknown = expectAsync(promiseBoolean).toBe(true)
481478
expectPromiseUnknown = expectAsync(promiseBoolean).not.toBe(true)
482479

483-
//@ts-expect-error
484480
expectPromiseVoid = expectAsync(promiseBoolean).toBe(true)
485-
//@ts-expect-error
486481
expectPromiseVoid = expectAsync(promiseBoolean).toBe(true)
487482
})
488483

@@ -492,13 +487,9 @@ describe('type assertions', () => {
492487
expectPromiseUnknown = expectAsync('text').toBe(wdioExpect.stringContaining('text'))
493488
expectPromiseUnknown = expectAsync('text').not.toBe(wdioExpect.stringContaining('text'))
494489

495-
//@ts-expect-error
496490
expectPromiseVoid = expectAsync('text').toBe(true)
497-
//@ts-expect-error
498491
expectPromiseVoid = expectAsync('text').not.toBe(true)
499-
//@ts-expect-error
500492
expectPromiseVoid = expectAsync('text').toBe(wdioExpect.stringContaining('text'))
501-
//@ts-expect-error
502493
expectPromiseVoid = expectAsync('text').not.toBe(wdioExpect.stringContaining('text'))
503494
})
504495
})
@@ -520,9 +511,7 @@ describe('type assertions', () => {
520511
})
521512

522513
it('should not support chainable and expect PromiseVoid with toBe', async () => {
523-
//@ts-expect-error
524514
expectPromiseVoid = expectAsync(chainableElement).toBe(true)
525-
//@ts-expect-error
526515
expectPromiseVoid = expectAsync(chainableElement).not.toBe(true)
527516
})
528517
})

0 commit comments

Comments
 (0)