diff --git a/package.json b/package.json index d293e1d19..dbc81bba3 100644 --- a/package.json +++ b/package.json @@ -63,6 +63,7 @@ "ts:mocha": "cd test-types/mocha && tsc --project ./tsconfig.json", "ts:jasmine": "cd test-types/jasmine && tsc --project ./tsconfig.json", "ts:jasmine-async": "cd test-types/jasmine-async && tsc --project ./tsconfig.json", + "checks:all": "npm run build && npm run compile && npm run tsc:root-types && npm run test && npm run ts", "watch": "npm run compile -- --watch", "prepare": "husky install" }, diff --git a/test-types/mocha/types-mocha.test.ts b/test-types/mocha/types-mocha.test.ts index 4d5ebd886..877ecdddf 100644 --- a/test-types/mocha/types-mocha.test.ts +++ b/test-types/mocha/types-mocha.test.ts @@ -7,6 +7,7 @@ describe('type assertions', () => { const element: WebdriverIO.Element = {} as unknown as WebdriverIO.Element const elementArray: WebdriverIO.ElementArray = [] as unknown as WebdriverIO.ElementArray + const elements: WebdriverIO.Element[] = [] as unknown as WebdriverIO.Element[] const networkMock: WebdriverIO.Mock = {} as unknown as WebdriverIO.Mock @@ -323,6 +324,26 @@ describe('type assertions', () => { expectVoid = expect(chainableArray).toBeElementsArrayOfSize({ lte: 10 }) }) + it('should work correctly when actual is element array', async () => { + expectPromiseVoid = expect(elementArray).toBeElementsArrayOfSize(5) + expectPromiseVoid = expect(elementArray).toBeElementsArrayOfSize({ lte: 10 }) + + // @ts-expect-error + expectVoid = expect(elementArray).toBeElementsArrayOfSize(5) + // @ts-expect-error + expectVoid = expect(elementArray).toBeElementsArrayOfSize({ lte: 10 }) + }) + + it('should work correctly when actual is element[]', async () => { + expectPromiseVoid = expect(elements).toBeElementsArrayOfSize(5) + expectPromiseVoid = expect(elements).toBeElementsArrayOfSize({ lte: 10 }) + + // @ts-expect-error + expectVoid = expect(elements).toBeElementsArrayOfSize(5) + // @ts-expect-error + expectVoid = expect(elements).toBeElementsArrayOfSize({ lte: 10 }) + }) + it('should not work when actual is not chainableArray', async () => { // @ts-expect-error await expect(chainableElement).toBeElementsArrayOfSize(5) diff --git a/types/expect-webdriverio.d.ts b/types/expect-webdriverio.d.ts index 429c12c32..15dabadcc 100644 --- a/types/expect-webdriverio.d.ts +++ b/types/expect-webdriverio.d.ts @@ -54,7 +54,7 @@ type WdioOnlyMaybePromiseLike = ElementPromise | ElementArrayPromise | Chainable */ type ElementOrArrayLike = ElementLike | ElementArrayLike type ElementLike = WebdriverIO.Element | ChainablePromiseElement -type ElementArrayLike = WebdriverIO.ElementArray | ChainablePromiseArray +type ElementArrayLike = WebdriverIO.ElementArray | ChainablePromiseArray | WebdriverIO.Element[] type MockPromise = Promise /**