Skip to content

Commit 5a7c88a

Browse files
authored
fix: tsc error with elements matcher and type WebdriverIO.Element[] (#1979)
* fix: tsc error with elements matcher and type `WebdriverIO.Element[]` `WebdriverIO.Element[]` needs to also be a `ElementArrayLike` * chore: add checks:all command to eases checks everything
1 parent f6c13c6 commit 5a7c88a

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"ts:mocha": "cd test-types/mocha && tsc --project ./tsconfig.json",
6464
"ts:jasmine": "cd test-types/jasmine && tsc --project ./tsconfig.json",
6565
"ts:jasmine-async": "cd test-types/jasmine-async && tsc --project ./tsconfig.json",
66+
"checks:all": "npm run build && npm run compile && npm run tsc:root-types && npm run test && npm run ts",
6667
"watch": "npm run compile -- --watch",
6768
"prepare": "husky install"
6869
},

test-types/mocha/types-mocha.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ describe('type assertions', () => {
77

88
const element: WebdriverIO.Element = {} as unknown as WebdriverIO.Element
99
const elementArray: WebdriverIO.ElementArray = [] as unknown as WebdriverIO.ElementArray
10+
const elements: WebdriverIO.Element[] = [] as unknown as WebdriverIO.Element[]
1011

1112
const networkMock: WebdriverIO.Mock = {} as unknown as WebdriverIO.Mock
1213

@@ -323,6 +324,26 @@ describe('type assertions', () => {
323324
expectVoid = expect(chainableArray).toBeElementsArrayOfSize({ lte: 10 })
324325
})
325326

327+
it('should work correctly when actual is element array', async () => {
328+
expectPromiseVoid = expect(elementArray).toBeElementsArrayOfSize(5)
329+
expectPromiseVoid = expect(elementArray).toBeElementsArrayOfSize({ lte: 10 })
330+
331+
// @ts-expect-error
332+
expectVoid = expect(elementArray).toBeElementsArrayOfSize(5)
333+
// @ts-expect-error
334+
expectVoid = expect(elementArray).toBeElementsArrayOfSize({ lte: 10 })
335+
})
336+
337+
it('should work correctly when actual is element[]', async () => {
338+
expectPromiseVoid = expect(elements).toBeElementsArrayOfSize(5)
339+
expectPromiseVoid = expect(elements).toBeElementsArrayOfSize({ lte: 10 })
340+
341+
// @ts-expect-error
342+
expectVoid = expect(elements).toBeElementsArrayOfSize(5)
343+
// @ts-expect-error
344+
expectVoid = expect(elements).toBeElementsArrayOfSize({ lte: 10 })
345+
})
346+
326347
it('should not work when actual is not chainableArray', async () => {
327348
// @ts-expect-error
328349
await expect(chainableElement).toBeElementsArrayOfSize(5)

types/expect-webdriverio.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ type WdioOnlyMaybePromiseLike = ElementPromise | ElementArrayPromise | Chainable
5454
*/
5555
type ElementOrArrayLike = ElementLike | ElementArrayLike
5656
type ElementLike = WebdriverIO.Element | ChainablePromiseElement
57-
type ElementArrayLike = WebdriverIO.ElementArray | ChainablePromiseArray
57+
type ElementArrayLike = WebdriverIO.ElementArray | ChainablePromiseArray | WebdriverIO.Element[]
5858
type MockPromise = Promise<WebdriverIO.Mock>
5959

6060
/**

0 commit comments

Comments
 (0)