-
-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* adds toBeBefore and toBeAfter matchers (#117) * updates documentation * adds gillesdemey to contributors * encode timezone into date constructors
- Loading branch information
1 parent
7a4ead0
commit 3fda960
Showing
13 changed files
with
223 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`.not.toBeAfter fails when given a later date 1`] = ` | ||
"<dim>expect(</><red>received</><dim>).not.toBeAfter(</><dim>)</> | ||
Expected date to be after <red>2018-06-01T22:00:00.000Z</> but received: | ||
<red>2018-06-02T22:00:00.000Z</>" | ||
`; | ||
exports[`.toBeAfter fails when given an earlier date 1`] = ` | ||
"<dim>expect(</><red>received</><dim>).toBeAfter(</><dim>)</> | ||
Expected date to be after <red>2018-06-02T22:00:00.000Z</> but received: | ||
<red>2018-06-01T22:00:00.000Z</>" | ||
`; |
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,26 @@ | ||
import { matcherHint, printReceived } from 'jest-matcher-utils'; | ||
|
||
import predicate from './predicate'; | ||
|
||
const passMessage = (received, after) => () => | ||
matcherHint('.not.toBeAfter', 'received', '') + | ||
'\n\n' + | ||
`Expected date to be after ${printReceived(after)} but received:\n` + | ||
` ${printReceived(received)}`; | ||
|
||
const failMessage = (received, after) => () => | ||
matcherHint('.toBeAfter', 'received', '') + | ||
'\n\n' + | ||
`Expected date to be after ${printReceived(after)} but received:\n` + | ||
` ${printReceived(received)}`; | ||
|
||
export default { | ||
toBeAfter: (date, after) => { | ||
const pass = predicate(date, after); | ||
if (pass) { | ||
return { pass: true, message: passMessage(date, after) }; | ||
} | ||
|
||
return { pass: false, message: failMessage(date, after) }; | ||
} | ||
}; |
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,30 @@ | ||
import matcher from './'; | ||
|
||
expect.extend(matcher); | ||
|
||
const EARLIER = new Date('2018-06-01T22:00:00.000Z'); | ||
const LATER = new Date('2018-06-02T22:00:00.000Z'); | ||
|
||
describe('.toBeAfter', () => { | ||
test('passes when given a later date', () => { | ||
expect(LATER).toBeAfter(EARLIER); | ||
}); | ||
|
||
test('fails when given an earlier date', () => { | ||
expect(() => { | ||
expect(EARLIER).toBeAfter(LATER); | ||
}).toThrowErrorMatchingSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('.not.toBeAfter', () => { | ||
test('passes when not given an earlier date', () => { | ||
expect(EARLIER).not.toBeAfter(LATER); | ||
}); | ||
|
||
test('fails when given a later date', () => { | ||
expect(() => { | ||
expect(LATER).not.toBeAfter(EARLIER); | ||
}).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,5 @@ | ||
function toBeAfter(date, after) { | ||
return date > after; | ||
} | ||
|
||
export default (date, after) => toBeAfter(date, after); |
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,14 @@ | ||
import predicate from './predicate'; | ||
|
||
const EARLIER = new Date('2018-06-01T22:00:00.000Z'); | ||
const LATER = new Date('2018-06-02T22:00:00.000Z'); | ||
|
||
describe('toBeAfter Predicate', () => { | ||
test('returns true when given an earlier date', () => { | ||
expect(predicate(LATER, EARLIER)).toBe(true); | ||
}); | ||
|
||
test('returns false when given a later date', () => { | ||
expect(predicate(EARLIER, LATER)).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`.not.toBeBefore fails when given an earlier date 1`] = ` | ||
"<dim>expect(</><red>received</><dim>).not.toBeBefore(</><dim>)</> | ||
Expected date to be before <red>2018-06-02T22:00:00.000Z</> but received: | ||
<red>2018-06-01T22:00:00.000Z</>" | ||
`; | ||
exports[`.toBeBefore fails when given a later date 1`] = ` | ||
"<dim>expect(</><red>received</><dim>).toBeBefore(</><dim>)</> | ||
Expected date to be before <red>2018-06-01T22:00:00.000Z</> but received: | ||
<red>2018-06-02T22:00:00.000Z</>" | ||
`; |
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,26 @@ | ||
import { matcherHint, printReceived } from 'jest-matcher-utils'; | ||
|
||
import predicate from './predicate'; | ||
|
||
const passMessage = (received, before) => () => | ||
matcherHint('.not.toBeBefore', 'received', '') + | ||
'\n\n' + | ||
`Expected date to be before ${printReceived(before)} but received:\n` + | ||
` ${printReceived(received)}`; | ||
|
||
const failMessage = (received, before) => () => | ||
matcherHint('.toBeBefore', 'received', '') + | ||
'\n\n' + | ||
`Expected date to be before ${printReceived(before)} but received:\n` + | ||
` ${printReceived(received)}`; | ||
|
||
export default { | ||
toBeBefore: (date, before) => { | ||
const pass = predicate(date, before); | ||
if (pass) { | ||
return { pass: true, message: passMessage(date, before) }; | ||
} | ||
|
||
return { pass: false, message: failMessage(date, before) }; | ||
} | ||
}; |
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,30 @@ | ||
import matcher from './'; | ||
|
||
expect.extend(matcher); | ||
|
||
const EARLIER = new Date('2018-06-01T22:00:00.000Z'); | ||
const LATER = new Date('2018-06-02T22:00:00.000Z'); | ||
|
||
describe('.toBeBefore', () => { | ||
test('passes when given an earlier date', () => { | ||
expect(EARLIER).toBeBefore(LATER); | ||
}); | ||
|
||
test('fails when given a later date', () => { | ||
expect(() => { | ||
expect(LATER).toBeBefore(EARLIER); | ||
}).toThrowErrorMatchingSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('.not.toBeBefore', () => { | ||
test('passes when given an earlier date', () => { | ||
expect(LATER).not.toBeBefore(EARLIER); | ||
}); | ||
|
||
test('fails when given an earlier date', () => { | ||
expect(() => { | ||
expect(EARLIER).not.toBeBefore(LATER); | ||
}).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,5 @@ | ||
function toBeBefore(date, before) { | ||
return date < before; | ||
} | ||
|
||
export default (date, before) => toBeBefore(date, before); |
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,14 @@ | ||
import predicate from './predicate'; | ||
|
||
const EARLIER = new Date('06/02/2018'); | ||
const LATER = new Date('07/02/2018'); | ||
|
||
describe('toBeAfter Predicate', () => { | ||
test('returns true when given a later date', () => { | ||
expect(predicate(EARLIER, LATER)).toBe(true); | ||
}); | ||
|
||
test('returns false when given an earlier date', () => { | ||
expect(predicate(LATER, EARLIER)).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