-
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
105 additions
and
0 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
15 changes: 15 additions & 0 deletions
15
src/matchers/toBeDateString/__snapshots__/index.test.js.snap
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.toBeDateString fails when given a date string 1`] = ` | ||
"<dim>expect(</><red>received</><dim>).not.toBeDateString(</><dim>)</> | ||
Expected value to not be a date string received: | ||
<red>\\"2018-01-01T13:00:00.000Z\\"</>" | ||
`; | ||
exports[`.toBeDateString fails when not given a date string 1`] = ` | ||
"<dim>expect(</><red>received</><dim>).toBeDateString(</><dim>)</> | ||
Expected value to be a date string received: | ||
<red>\\"not a date\\"</>" | ||
`; |
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 => () => | ||
matcherHint('.not.toBeDateString', 'received', '') + | ||
'\n\n' + | ||
'Expected value to not be a date string received:\n' + | ||
` ${printReceived(received)}`; | ||
|
||
const failMessage = received => () => | ||
matcherHint('.toBeDateString', 'received', '') + | ||
'\n\n' + | ||
'Expected value to be a date string received:\n' + | ||
` ${printReceived(received)}`; | ||
|
||
export default { | ||
toBeDateString: 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,23 @@ | ||
import matcher from './'; | ||
|
||
expect.extend(matcher); | ||
|
||
describe('.toBeDateString', () => { | ||
test('passes when given a date string', () => { | ||
expect(new Date().toISOString()).toBeDateString(); | ||
}); | ||
|
||
test('fails when not given a date string', () => { | ||
expect(() => expect('not a date').toBeDateString()).toThrowErrorMatchingSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('.not.toBeDateString', () => { | ||
test('passes when not given a date string', () => { | ||
expect('not a date').not.toBeDateString(); | ||
}); | ||
|
||
test('fails when given a date string', () => { | ||
expect(() => expect('2018-01-01T13:00:00.000Z').not.toBeDateString()).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,3 @@ | ||
const isDateString = value => !isNaN(Date.parse(value)); | ||
|
||
export default isDateString; |
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,11 @@ | ||
import predicate from './predicate'; | ||
|
||
describe('toBeDateString Predicate', () => { | ||
test('returns true when given a date string', () => { | ||
expect(predicate(new Date().toISOString())).toBe(true); | ||
}); | ||
|
||
test('returns false when given a non date string', () => { | ||
expect(predicate('not a date')).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