-
-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add toBeFalse predicate * Add toBeFalse matcher * Update docs and add contributor * Add toBeFalse to matchers index
- Loading branch information
1 parent
3fdb024
commit 6b27c74
Showing
8 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`.not.toBeFalse fails when given false 1`] = ` | ||
"<dim>expect(</><red>received</><dim>).not.toBeFalse(</><dim>)</> | ||
Expected value to not be false received: | ||
<red>false</>" | ||
`; | ||
exports[`.toBeFalse fails when not given false 1`] = ` | ||
"<dim>expect(</><red>received</><dim>).toBeFalse(</><dim>)</> | ||
Expected value to be false: | ||
<green>false</> | ||
Received: | ||
<red>true</>" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { matcherHint, printExpected, printReceived } from 'jest-matcher-utils'; | ||
|
||
import predicate from './predicate'; | ||
|
||
const passMessage = received => () => | ||
matcherHint('.not.toBeFalse', 'received', '') + | ||
'\n\n' + | ||
'Expected value to not be false received:\n' + | ||
` ${printReceived(received)}`; | ||
|
||
const failMessage = received => () => | ||
matcherHint('.toBeFalse', 'received', '') + | ||
'\n\n' + | ||
'Expected value to be false:\n' + | ||
` ${printExpected(false)}\n` + | ||
'Received:\n' + | ||
` ${printReceived(received)}`; | ||
|
||
export default { | ||
toBeFalse: expected => { | ||
const pass = predicate(expected); | ||
if (pass) { | ||
return { pass: true, message: passMessage(expected) }; | ||
} | ||
|
||
return { pass: false, message: failMessage(expected) }; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import each from 'jest-each'; | ||
|
||
import matcher from './'; | ||
|
||
expect.extend(matcher); | ||
|
||
describe('.toBeFalse', () => { | ||
it('passes when given false', () => { | ||
expect(false).toBeFalse(); | ||
}); | ||
|
||
it('fails when not given false', () => { | ||
expect(() => expect(true).toBeFalse()).toThrowErrorMatchingSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('.not.toBeFalse', () => { | ||
each([[true], [''], [0], [{}], [[]], [() => {}], [undefined], [null], [NaN]]).it( | ||
'passes when not given false: %s', | ||
given => { | ||
expect(given).not.toBeFalse(); | ||
} | ||
); | ||
|
||
it('fails when given false', () => { | ||
expect(() => expect(false).not.toBeFalse()).toThrowErrorMatchingSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default expected => expected === false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import each from 'jest-each'; | ||
import predicate from './predicate'; | ||
|
||
describe('toBeFalse Predicate', () => { | ||
it('returns true when given false', () => { | ||
expect(predicate(false)).toBe(true); | ||
}); | ||
|
||
each([[true], [''], [0], [{}], [[]], [() => {}], [undefined], [null], [NaN]]).it( | ||
'returns false when given: %s', | ||
given => { | ||
expect(predicate(given)).toBe(false); | ||
} | ||
); | ||
}); |