forked from jest-community/jest-extended
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Pass & Fail matchers (jest-community#204)
- Loading branch information
1 parent
ff02ff1
commit 61c92f8
Showing
12 changed files
with
92 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`.fail fails with message 1`] = `"This shouldn't fail!"`; | ||
|
||
exports[`.fail fails without message 1`] = `"fails by .fail() assertion"`; |
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,10 @@ | ||
import predicate from './predicate'; | ||
|
||
const failMessage = message => { | ||
if (message) return () => message; | ||
else return () => 'fails by .fail() assertion'; | ||
}; | ||
|
||
export default { | ||
fail: (expected, message) => ({ pass: predicate(), message: failMessage(message) }), | ||
}; |
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,21 @@ | ||
import matcher from './'; | ||
|
||
expect.extend(matcher); | ||
|
||
describe('.fail', () => { | ||
test('fails without message', () => { | ||
expect(() => expect().fail()).toThrowErrorMatchingSnapshot(); | ||
}); | ||
test('fails with message', () => { | ||
expect(() => expect().fail("This shouldn't fail!")).toThrowErrorMatchingSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('.not.fail', () => { | ||
test('does not fail without message', () => { | ||
expect().not.fail(); | ||
}); | ||
test('does not fail with message', () => { | ||
expect().not.fail('this should fail!'); | ||
}); | ||
}); |
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 () => 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,7 @@ | ||
import predicate from './predicate'; | ||
|
||
describe('fail Predicate', () => { | ||
test('returns false', () => { | ||
expect(predicate()).toBe(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
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,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`.not.pass does not pass, has no message 1`] = `"passes by .pass() assertion"`; | ||
|
||
exports[`.not.pass does not.pass, has no message 1`] = `"This should not pass!"`; |
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,10 @@ | ||
import predicate from './predicate'; | ||
|
||
const passMessage = message => { | ||
if (message) return () => message; | ||
else return () => 'passes by .pass() assertion'; | ||
}; | ||
|
||
export default { | ||
pass: (expected, message) => ({ pass: predicate(), message: passMessage(message) }), | ||
}; |
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,21 @@ | ||
import matcher from './'; | ||
|
||
expect.extend(matcher); | ||
|
||
describe('.pass', () => { | ||
test('passes without message', () => { | ||
expect().pass(); | ||
}); | ||
test('passes with message', () => { | ||
expect().pass('this should pass!'); | ||
}); | ||
}); | ||
|
||
describe('.not.pass', () => { | ||
test('does not pass, has no message', () => { | ||
expect(() => expect().not.pass()).toThrowErrorMatchingSnapshot(); | ||
}); | ||
test('does not.pass, has no message', () => { | ||
expect(() => expect().not.pass('This should not pass!')).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 () => 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,7 @@ | ||
import predicate from './predicate'; | ||
|
||
describe('true Predicate', () => { | ||
test('returns true', () => { | ||
expect(predicate()).toBe(true); | ||
}); | ||
}); |