Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
21 changes: 21 additions & 0 deletions test-types/mocha/types-mocha.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion types/expect-webdriverio.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebdriverIO.Mock>

/**
Expand Down