Skip to content

Commit 35dc4b1

Browse files
committed
fix rebase + add more UT typing cases
1 parent ca4d073 commit 35dc4b1

File tree

6 files changed

+46
-27
lines changed

6 files changed

+46
-27
lines changed

src/matchers/element/toHaveAttribute.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@ async function toHaveAttributeFn(received: ChainablePromiseElement | WebdriverIO
5656
let el = await received
5757

5858
const pass = await waitUntil(async () => {
59+
// @ts-ignore TODO dprevost fix me
5960
const result = await executeCommand.call(this, el, conditionAttr, {}, [attribute])
6061
el = result.el as WebdriverIO.Element
6162

6263
return result.success
6364
}, isNot, {})
6465

66+
// @ts-ignore TODO dprevost fix me
6567
const message = enhanceError(el, !isNot, pass, this, verb, expectation, attribute, {})
6668

6769
return {
@@ -84,6 +86,7 @@ export async function toHaveAttribute(
8486

8587
const result = typeof value !== 'undefined'
8688
// Name and value is passed in e.g. el.toHaveAttribute('attr', 'value', (opts))
89+
// @ts-ignore TODO dprevost fix me
8790
? await toHaveAttributeAndValue.call(this, received, attribute, value, options)
8891
// Only name is passed in e.g. el.toHaveAttribute('attr')
8992
: await toHaveAttributeFn.call(this, received, attribute)

src/matchers/element/toHaveClass.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export async function toHaveElementClass(
8484
* @deprecated
8585
*/
8686
export function toHaveClassContaining(el: WebdriverIO.Element, className: string | RegExp | ExpectWebdriverIO.PartialMatcher, options: ExpectWebdriverIO.StringOptions = DEFAULT_OPTIONS) {
87+
// @ts-ignore TODO dprevost fix me
8788
return toHaveAttributeAndValue.call(this, el, 'class', className, {
8889
...options,
8990
containing: true

src/matchers/element/toHaveHref.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export async function toHaveHref(
1313
options,
1414
})
1515

16+
// @ts-ignore TODO dprevost fix me
1617
const result = await toHaveAttributeAndValue.call(this, el, 'href', expectedValue, options)
1718

1819
await options.afterAssertion?.({

src/matchers/element/toHaveId.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export async function toHaveId(
1313
options,
1414
})
1515

16+
// @ts-ignore TODO dprevost fix me
1617
const result: ExpectWebdriverIO.AssertionResult = await toHaveAttributeAndValue.call(this, el, 'id', expectedValue, options)
1718

1819
await options.afterAssertion?.({

test-types/jest/types-jest.test.ts

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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(/text/)
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([/text1/, /text2/])
84+
const expectPromise6: Promise<void> = expect(element).toHaveText(['text1', /text1/, 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 () => {

types/expect-webdriverio.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,7 @@ interface WdioCustomMatchers<R, T = unknown> {
247247
* await expect(elem).toHaveText(['Coffee', 'Tea', 'Milk'])
248248
* ```
249249
*/
250-
toHaveText(
251-
text: string | RegExp | ExpectWebdriverIO.PartialMatcher | Array<string | RegExp | ExpectWebdriverIO.PartialMatcher>,
252-
) => Promise<R> : never
250+
toHaveText: T extends ElementOrArrayLike ? (text: string | RegExp | ExpectWebdriverIO.PartialMatcher | Array<string | RegExp | ExpectWebdriverIO.PartialMatcher>) => Promise<R> : never
253251

254252
/**
255253
* `WebdriverIO.Element` -> `getHTML`

0 commit comments

Comments
 (0)