Skip to content

Commit

Permalink
Add fail tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuibu committed Nov 20, 2022
1 parent a522080 commit 613425b
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions packages/expect/src/__tests__/toThrowMatchers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,39 @@ describe.each(['toThrowError', 'toThrow'] as const)('%s', toThrow => {
});

test('isNot true, incorrect cause', () => {
// less than v16 does not yet support Error.cause
if (Number(process.version.split('.')[0].slice(1)) < 16) {
expect(true).toBe(true);
} else {
// only v16 or higher support Error.cause
if (Number(process.version.split('.')[0].slice(1)) >= 16) {
jestExpect(() => {
throw new Error('good', {cause: errorA});
}).not[toThrow](expected);
}
});
});

describe('fail', () => {
// only v16 or higher support Error.cause
if (Number(process.version.split('.')[0].slice(1)) >= 16) {
test('isNot false, incorrect message', () => {
expect(() =>
jestExpect(() => {
throw new Error('bad', {cause: errorB});
})[toThrow](expected),
).toThrow(
/^(?=.*Expected message and cause: ).*Received message and cause: /s,
);
});

test('isNot true, incorrect cause', () => {
expect(() =>
jestExpect(() => {
throw new Error('good', {cause: errorA});
})[toThrow](expected),
).toThrow(
/^(?=.*Expected message and cause: ).*Received message and cause: /s,
);
});
}
});
});

describe('asymmetric', () => {
Expand Down

0 comments on commit 613425b

Please sign in to comment.