Skip to content

Commit d0474ee

Browse files
committed
Allow fail to work in try/catch
1 parent 1f88101 commit d0474ee

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/matchers/fail.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export function fail(_, message) {
2+
this.dontThrow();
23
return {
34
pass: false,
45
message: () => (message ? message : 'fails by .fail() assertion'),

test/matchers/__snapshots__/fail.test.js.snap

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/matchers/fail.test.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@ import * as matcher from 'src/matchers/fail';
33
expect.extend(matcher);
44

55
describe('.fail', () => {
6-
test('fails without message', () => {
7-
expect(() => expect().fail()).toThrowErrorMatchingSnapshot();
6+
xtest('fails without message', () => {
7+
expect().fail(); // This should fail!
88
});
9-
test('fails with message', () => {
10-
expect(() => expect().fail("This shouldn't fail!")).toThrowErrorMatchingSnapshot();
9+
xtest('fails with message', () => {
10+
expect().fail('This should fail!');
11+
});
12+
xtest('fails when invoked in a try/catch', () => {
13+
try {
14+
expect().fail();
15+
} catch (error) {
16+
expect('this assertion').toBe('not checked');
17+
}
1118
});
1219
});
1320

@@ -16,6 +23,6 @@ describe('.not.fail', () => {
1623
expect().not.fail();
1724
});
1825
test('does not fail with message', () => {
19-
expect().not.fail('this should fail!');
26+
expect().not.fail('this should not fail!');
2027
});
2128
});

0 commit comments

Comments
 (0)