Skip to content

Commit

Permalink
Add tests for when toBeTrue fails
Browse files Browse the repository at this point in the history
  • Loading branch information
mattphillips committed Oct 20, 2017
1 parent 58ba3c8 commit 892c905
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.1",
"description": "Additional Jest matchers",
"main": "dist/index.js",
"files":[
"files": [
"dist",
"README.md",
"LICENSE"
Expand Down Expand Up @@ -57,7 +57,8 @@
"jest": "^21.2.1",
"jest-each": "^0.3.1",
"lint-staged": "^4.3.0",
"prettier": "^1.7.4"
"prettier": "^1.7.4",
"pretty-format": "^21.2.1"
},
"dependencies": {
"chalk": "^2.2.0",
Expand All @@ -78,6 +79,9 @@
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"snapshotSerializers": [
"pretty-format/build/plugins/convert_ansi.js"
],
"coverageThreshold": {
"global": {
"branches": 100,
Expand Down
18 changes: 18 additions & 0 deletions src/matchers/toBeTrue/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`.not.toBeTrue fails when given true 1`] = `
"<dim>expect(</><red>received</><dim>).not.toBeTrue(</><dim>)</>
Expected value to not be true:
Received:
<red>true</>"
`;
exports[`toBeTrue fails when not given true 1`] = `
"<dim>expect(</><red>received</><dim>).toBeTrue(</><dim>)</>
Expected value to be true:
<green>true</>
Received:
<red>false</>"
`;
14 changes: 12 additions & 2 deletions src/matchers/toBeTrue/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@ import each from 'jest-each';

import matcher from './';

describe('toBeTrue', () => {
expect.extend(matcher);
expect.extend(matcher);

describe('toBeTrue', () => {
it('passes when given true', () => {
expect(true).toBeTrue();
});

it('fails when not given true', () => {
expect(() => expect(false).toBeTrue()).toThrowErrorMatchingSnapshot();
});
});

describe('.not.toBeTrue', () => {
each([[false], [''], [0], [{}], [[]], [() => {}], [undefined], [null], [NaN]]).it(
'passes when not given true: %s',
given => {
expect(given).not.toBeTrue();
}
);

it('fails when given true', () => {
expect(() => expect(true).not.toBeTrue()).toThrowErrorMatchingSnapshot();
});
});

0 comments on commit 892c905

Please sign in to comment.