Skip to content

Commit 95d97bd

Browse files
(bugfix): allow failing condition to fail with proper error (#1445)
* (chore): update deps * (bugfix): allow failing condition to fail with proper error
1 parent bde595d commit 95d97bd

19 files changed

+274
-143
lines changed

package-lock.json

Lines changed: 211 additions & 74 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"compile": "tsc --build tsconfig.build.json",
4949
"test": "run-s test:*",
5050
"test:lint": "eslint . --ext .js,.jsx,.ts,.tsx",
51-
"test:unit": "vitest",
51+
"test:unit": "vitest --run",
5252
"test:types": "node test-types/copy && npm run ts && npm run clean:tests",
5353
"ts": "run-s ts:*",
5454
"ts:default": "cd test-types/default && tsc -p ./tsconfig.json --incremental",
@@ -61,30 +61,30 @@
6161
"@types/debug": "^4.1.12",
6262
"@types/jest": "^29.5.11",
6363
"@types/lodash.isequal": "^4.5.8",
64-
"@types/node": "^20.10.6",
65-
"@typescript-eslint/eslint-plugin": "^6.17.0",
66-
"@typescript-eslint/parser": "^6.17.0",
67-
"@vitest/coverage-v8": "^1.1.3",
68-
"c8": "^9.0.0",
64+
"@types/node": "^20.11.14",
65+
"@typescript-eslint/eslint-plugin": "^6.20.0",
66+
"@typescript-eslint/parser": "^6.20.0",
67+
"@vitest/coverage-v8": "^1.2.2",
68+
"c8": "^9.1.0",
6969
"eslint": "^8.56.0",
7070
"eslint-plugin-import": "^2.29.1",
7171
"eslint-plugin-unicorn": "^50.0.1",
72-
"husky": "^9.0.6",
72+
"husky": "^9.0.7",
7373
"npm-run-all": "^4.1.5",
74-
"release-it": "^17.0.1",
74+
"release-it": "^17.0.3",
7575
"rimraf": "^5.0.5",
7676
"shelljs": "^0.8.5",
7777
"typescript": "^5.3.3",
7878
"vitest": "1.2.2",
7979
"webdriverio": "8.29.1"
8080
},
8181
"optionalDependencies": {
82-
"@wdio/globals": "^8.27.0",
83-
"@wdio/logger": "^8.24.12",
84-
"webdriverio": "^8.27.0"
82+
"@wdio/globals": "^8.29.3",
83+
"@wdio/logger": "^8.28.0",
84+
"webdriverio": "^8.29.3"
8585
},
8686
"dependencies": {
87-
"@vitest/snapshot": "^1.2.1",
87+
"@vitest/snapshot": "^1.2.2",
8888
"expect": "^29.7.0",
8989
"jest-matcher-utils": "^29.7.0",
9090
"lodash.isequal": "^4.5.0"

src/matchers/element/toBeClickable.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@ export async function toBeClickable(
1212
options,
1313
})
1414

15-
const result = await executeCommandBe.call(this, received, async el => {
16-
try {
17-
return el.isClickable()
18-
} catch {
19-
return false
20-
}
21-
}, options)
15+
const result = await executeCommandBe.call(this, received, el => el.isClickable(), options)
2216

2317
await options.afterAssertion?.({
2418
matcherName: 'toBeClickable',

src/matchers/element/toBeDisplayed.ts

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

16-
const result = await executeCommandBe.call(this, received, async el => {
17-
try {
18-
return el.isDisplayed()
19-
} catch {
20-
return false
21-
}
22-
}, options)
16+
const result = await executeCommandBe.call(this, received, el => el.isDisplayed(), options)
2317

2418
await options.afterAssertion?.({
2519
matcherName: 'toBeDisplayed',

src/matchers/element/toBeDisplayedInViewport.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@ export async function toBeDisplayedInViewport(
1212
options,
1313
})
1414

15-
const result = await executeCommandBe.call(this, received, async el => {
16-
try {
17-
return el.isDisplayedInViewport()
18-
} catch {
19-
return false
20-
}
21-
}, options)
15+
const result = await executeCommandBe.call(this, received, el => el.isDisplayedInViewport(), options)
2216

2317
await options.afterAssertion?.({
2418
matcherName: 'toBeDisplayedInViewport',

src/matchers/element/toBeExisting.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@ export async function toExist(
1414
options,
1515
})
1616

17-
const result = await executeCommandBe.call(this, received, async el => {
18-
try {
19-
return el.isExisting()
20-
} catch {
21-
return false
22-
}
23-
}, options)
17+
const result = await executeCommandBe.call(this, received, el => el.isExisting(), options)
2418

2519
await options.afterAssertion?.({
2620
matcherName: 'toExist',

src/utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ const waitUntil = async (
3030
return await condition()
3131
}
3232

33+
let error: Error | undefined
34+
3335
// wait for condition to be truthy
3436
try {
35-
let error
3637
const start = Date.now()
3738
// eslint-disable-next-line no-constant-condition
3839
while (true) {
@@ -43,6 +44,7 @@ const waitUntil = async (
4344
error = undefined
4445
try {
4546
const result = isNot !== (await condition())
47+
error = undefined
4648
if (result) {
4749
break
4850
}
@@ -59,6 +61,10 @@ const waitUntil = async (
5961

6062
return !isNot
6163
} catch (err) {
64+
if (error) {
65+
throw error
66+
}
67+
6268
return isNot
6369
}
6470
}

test/matchers/beMatchers.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ describe('be* matchers', () => {
4242
throw new Error('some error')
4343
}
4444

45-
const result = await fn.call({}, el)
46-
expect(result.pass).toBe(false)
45+
await expect(() => fn.call({}, el, 10, {}))
46+
.rejects.toThrow('some error')
4747
})
4848

4949
test('success on the first attempt', async () => {

test/matchers/browserMatchers.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ describe('browser matchers', () => {
4040
throw new Error('some error')
4141
}
4242

43-
const result = await fn.call({}, browser, validText, { trim: false })
44-
expect(result.pass).toBe(false)
43+
await expect(() => fn.call({}, browser, validText, { trim: false }))
44+
.rejects.toThrow('some error')
4545
})
4646

4747
test('success on the first attempt', async () => {

test/matchers/element/toBeDisabled.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ describe('toBeDisabled', () => {
4444
throw new Error('some error')
4545
}
4646

47-
const result = await toBeDisabled.call({}, el)
48-
expect(result.pass).toBe(false)
47+
await expect(() => toBeDisabled.call({}, el))
48+
.rejects.toThrow('some error')
4949
})
5050

5151
test('success on the first attempt', async () => {

0 commit comments

Comments
 (0)