Skip to content

Commit 874cec6

Browse files
committed
chore: add an errorMessage parameter to expectToFail() util
1 parent 8e9abf9 commit 874cec6

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tests/e2e/utils/utils.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11

2-
export function expectToFail(fn: () => Promise<any>): Promise<void> {
2+
export function expectToFail(fn: () => Promise<any>, errorMessage?: string): Promise<void> {
33
return fn()
44
.then(() => {
5-
throw new Error(`Function ${fn.source} was expected to fail, but succeeded.`);
6-
}, () => {});
5+
const functionSource = fn.name || (<any>fn).source || fn.toString();
6+
const errorDetails = errorMessage ? `\n\tDetails:\n\t${errorMessage}` : '';
7+
throw new Error(
8+
`Function ${functionSource} was expected to fail, but succeeded.${errorDetails}`);
9+
}, () => { });
710
}
811

912
export function isMobileTest() {

0 commit comments

Comments
 (0)