Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuibu committed Nov 12, 2022
1 parent 89d160d commit 4620977
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
52 changes: 52 additions & 0 deletions packages/expect/src/__tests__/toThrowMatchers.test.ts
Expand Up @@ -278,6 +278,58 @@ describe.each(['toThrowError', 'toThrow'] as const)('%s', toThrow => {
});
});

describe('error message and cause', () => {
const errorA = new Error('A');
const errorB = new Error('B', {cause: errorA});
const expected = new Error('good', {cause: errorB});

describe('pass', () => {
test('isNot false', () => {
jestExpect(() => {
throw new Error('good', {cause: errorB});
})[toThrow](expected);
});

test('isNot true, incorrect message', () => {
jestExpect(() => {
throw new Error('bad', {cause: errorB});
}).not[toThrow](expected);
});

test('isNot true, incorrect cause', () => {
jestExpect(() => {
throw new Error('good', {cause: errorA});
}).not[toThrow](expected);
});
});

describe('fail', () => {
test('isNot false, incorrect message', () => {
expect(() =>
jestExpect(() => {
throw new Error('bad', {cause: errorB});
})[toThrow](expected),
).toThrowErrorMatchingSnapshot();
});

test('isNot false, incorrect cause', () => {
expect(() =>
jestExpect(() => {
throw new Error('good', {cause: errorA});
})[toThrow](expected),
).toThrowErrorMatchingSnapshot();
});

test('isNot true, hoge', () => {
expect(() =>
jestExpect(() => {
throw new Error('good', {cause: errorB});
}).not[toThrow]({cause: errorB, message: 'good'}),
).toThrowErrorMatchingSnapshot();
});
});
});

describe('asymmetric', () => {
describe('any-Class', () => {
describe('pass', () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/expect/src/__tests__/tsconfig.json
@@ -1,5 +1,8 @@
{
"extends": "../../../../tsconfig.test.json",
"compilerOptions": {
"lib": ["es2022"]
},
"include": ["./**/*"],
"references": [{"path": "../../"}]
}

0 comments on commit 4620977

Please sign in to comment.