diff --git a/.all-contributorsrc b/.all-contributorsrc
index 4453790b..95deef08 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -326,6 +326,19 @@
"avatar_url": "https://avatars0.githubusercontent.com/u/15064535?v=4",
"profile": "https://github.com/LucianBuzzo",
"contributions": []
+ },
+ {
+ "login": "thiagodp",
+ "name": "Thiago Delgado Pinto",
+ "avatar_url": "https://avatars3.githubusercontent.com/u/2997844?v=4",
+ "profile": "https://github.com/thiagodp",
+ "contributions": [
+ "code",
+ "doc",
+ "example",
+ "ideas",
+ "test"
+ ]
}
]
}
diff --git a/README.md b/README.md
index 0c3e1d4b..0ff83c7f 100644
--- a/README.md
+++ b/README.md
@@ -52,7 +52,8 @@ If you've come here to help contribute - Thanks! Take a look at the [contributin
* [.toBeTrue()](#tobetrue)
* [.toBeFalse()](#tobefalse)
* [~~Date~~](#date)
- * _No APIs proposed yet_
+ * Proposal in #117 (under development)
+
* [Function](#function)
* [.toBeFunction()](#tobefunction)
* [Mock](#mock)
@@ -298,7 +299,20 @@ test('returns false', () => {
### ~~Date~~
-_No APIs proposed yet_
+Proposal in #117 (*under development*)
+
+### .toBeDate()
+
+Use `.toBeDate` when checking if a value is a `Date`.
+
+```js
+test('passes when value is a date', () => {
+ expect(new Date()).toBeDate();
+ expect('01/01/2018').not.toBeDate();
+ expect(new Date('01/01/2018').toBeDate();
+ expect(undefined).not.toBeDate();
+});
+```
### Function
@@ -748,7 +762,7 @@ test('passes when value includes all substrings', () => {
| [![](https://avatars1.githubusercontent.com/u/159848?v=4)
Andrew Hayward](http://andrewhayward.net)
[π»](https://github.com/mattphillips/jest-extended/commits?author=andrewhayward "Code") [β οΈ](https://github.com/mattphillips/jest-extended/commits?author=andrewhayward "Tests") | [![](https://avatars3.githubusercontent.com/u/6209178?v=4)
Oliver Schneider](https://ols.io)
[π»](https://github.com/mattphillips/jest-extended/commits?author=olsio "Code") [β οΈ](https://github.com/mattphillips/jest-extended/commits?author=olsio "Tests") | [![](https://avatars1.githubusercontent.com/u/22359375?s=460&v=4)
Tyle Whalen](https://github.com/tjwhalen16)
[π»](https://github.com/mattphillips/jest-extended/commits?author=tjwhalen16 "Code") [π](https://github.com/mattphillips/jest-extended/commits?author=tjwhalen16 "Documentation") | [![](https://avatars2.githubusercontent.com/u/17944339?v=4)
Martius](https://github.com/martiuslim)
[π»](https://github.com/mattphillips/jest-extended/commits?author=martiuslim "Code") [β οΈ](https://github.com/mattphillips/jest-extended/commits?author=martiuslim "Tests") | [![](https://avatars2.githubusercontent.com/u/10856932?v=4)
Eli Collis](https://github.com/ecollis6)
[π»](https://github.com/mattphillips/jest-extended/commits?author=ecollis6 "Code") | [![](https://avatars0.githubusercontent.com/u/10706203?v=4)
Marcin LichwaΕa](https://github.com/marcinlichwala)
[π»](https://github.com/mattphillips/jest-extended/commits?author=marcinlichwala "Code") [β οΈ](https://github.com/mattphillips/jest-extended/commits?author=marcinlichwala "Tests") | [![](https://avatars3.githubusercontent.com/u/1984733?v=4)
Massimo Prencipe](https://github.com/mprencipe)
[π»](https://github.com/mattphillips/jest-extended/commits?author=mprencipe "Code") [β οΈ](https://github.com/mattphillips/jest-extended/commits?author=mprencipe "Tests") |
| [![](https://avatars2.githubusercontent.com/u/33098064?v=4)
mjmiles](https://github.com/mjmiles)
[π»](https://github.com/mattphillips/jest-extended/commits?author=mjmiles "Code") [π](https://github.com/mattphillips/jest-extended/commits?author=mjmiles "Documentation") | [![](https://avatars1.githubusercontent.com/u/13333582?v=4)
Gary Meehan](https://github.com/garmeeh)
[π»](https://github.com/mattphillips/jest-extended/commits?author=garmeeh "Code") [π](https://github.com/mattphillips/jest-extended/commits?author=garmeeh "Documentation") [β οΈ](https://github.com/mattphillips/jest-extended/commits?author=garmeeh "Tests") | [![](https://avatars2.githubusercontent.com/u/3191489?v=4)
Fredrik MΓ€kilΓ€](https://github.com/GitHug)
[π»](https://github.com/mattphillips/jest-extended/commits?author=GitHug "Code") [β οΈ](https://github.com/mattphillips/jest-extended/commits?author=GitHug "Tests") | [![](https://avatars2.githubusercontent.com/u/9046616?v=4)
Daniel Reinoso](http://kloc.io/)
[π»](https://github.com/mattphillips/jest-extended/commits?author=danielr18 "Code") [β οΈ](https://github.com/mattphillips/jest-extended/commits?author=danielr18 "Tests") | [![](https://avatars1.githubusercontent.com/u/4359781?v=4)
Chris Hut](https://github.com/tophernuts)
[π»](https://github.com/mattphillips/jest-extended/commits?author=tophernuts "Code") [β οΈ](https://github.com/mattphillips/jest-extended/commits?author=tophernuts "Tests") | [![](https://avatars2.githubusercontent.com/u/1513183?v=4)
Kelvin Ly](https://github.com/cactorium)
[π»](https://github.com/mattphillips/jest-extended/commits?author=cactorium "Code") [β οΈ](https://github.com/mattphillips/jest-extended/commits?author=cactorium "Tests") | [![](https://avatars0.githubusercontent.com/u/11182826?v=4)
Francis Ngo](https://github.com/francisngo)
[π»](https://github.com/mattphillips/jest-extended/commits?author=francisngo "Code") [β οΈ](https://github.com/mattphillips/jest-extended/commits?author=francisngo "Tests") |
| [![](https://avatars1.githubusercontent.com/u/10330923?v=4)
Amish Shah](https://hydrabolt.me/)
[π»](https://github.com/mattphillips/jest-extended/commits?author=hydrabolt "Code") [β οΈ](https://github.com/mattphillips/jest-extended/commits?author=hydrabolt "Tests") | [![](https://avatars3.githubusercontent.com/u/2045206?v=4)
Dave Cooper](http://davecooper.org)
[π»](https://github.com/mattphillips/jest-extended/commits?author=grug "Code") [β οΈ](https://github.com/mattphillips/jest-extended/commits?author=grug "Tests") | [![](https://avatars3.githubusercontent.com/u/3630495?v=4)
Swann Polydor](https://github.com/soueuls)
[π»](https://github.com/mattphillips/jest-extended/commits?author=soueuls "Code") [β οΈ](https://github.com/mattphillips/jest-extended/commits?author=soueuls "Tests") | [![](https://avatars1.githubusercontent.com/u/2027003?v=4)
vikneshwar](https://github.com/vikneshwar)
[π»](https://github.com/mattphillips/jest-extended/commits?author=vikneshwar "Code") [β οΈ](https://github.com/mattphillips/jest-extended/commits?author=vikneshwar "Tests") | [![](https://avatars1.githubusercontent.com/u/1243921?v=4)
Budi Irawan](http://budiirawan.com)
[π»](https://github.com/mattphillips/jest-extended/commits?author=deerawan "Code") [β οΈ](https://github.com/mattphillips/jest-extended/commits?author=deerawan "Tests") | [![](https://avatars2.githubusercontent.com/u/980783?v=4)
Tejas Bubane](http://foss-geek.blogspot.com/)
[π»](https://github.com/mattphillips/jest-extended/commits?author=tejasbubane "Code") | [![](https://avatars2.githubusercontent.com/u/13134653?v=4)
Subinoy Ghosh](https://github.com/subinoy7)
[π»](https://github.com/mattphillips/jest-extended/commits?author=subinoy7 "Code") [β οΈ](https://github.com/mattphillips/jest-extended/commits?author=subinoy7 "Tests") |
-| [![](https://avatars1.githubusercontent.com/u/1404810?v=4)
Simen Bekkhus](https://github.com/SimenB)
[π](https://github.com/mattphillips/jest-extended/commits?author=SimenB "Documentation") | [![](https://avatars2.githubusercontent.com/u/49038?v=4)
Orta](http://orta.io)
[π](https://github.com/mattphillips/jest-extended/commits?author=orta "Documentation") | [![](https://avatars3.githubusercontent.com/u/17221813?v=4)
Tom](https://jsdevtom.com)
[π»](https://github.com/mattphillips/jest-extended/commits?author=jsdevtom "Code") [π](https://github.com/mattphillips/jest-extended/commits?author=jsdevtom "Documentation") [π‘](#example-jsdevtom "Examples") [β οΈ](https://github.com/mattphillips/jest-extended/commits?author=jsdevtom "Tests") | [![](https://avatars0.githubusercontent.com/u/15064535?v=4)
Lucian Buzzo](https://github.com/LucianBuzzo)
|
+| [![](https://avatars1.githubusercontent.com/u/1404810?v=4)
Simen Bekkhus](https://github.com/SimenB)
[π](https://github.com/mattphillips/jest-extended/commits?author=SimenB "Documentation") | [![](https://avatars2.githubusercontent.com/u/49038?v=4)
Orta](http://orta.io)
[π](https://github.com/mattphillips/jest-extended/commits?author=orta "Documentation") | [![](https://avatars3.githubusercontent.com/u/17221813?v=4)
Tom](https://jsdevtom.com)
[π»](https://github.com/mattphillips/jest-extended/commits?author=jsdevtom "Code") [π](https://github.com/mattphillips/jest-extended/commits?author=jsdevtom "Documentation") [π‘](#example-jsdevtom "Examples") [β οΈ](https://github.com/mattphillips/jest-extended/commits?author=jsdevtom "Tests") | [![](https://avatars0.githubusercontent.com/u/15064535?v=4)
Lucian Buzzo](https://github.com/LucianBuzzo)
| [![](https://avatars3.githubusercontent.com/u/2997844?v=4)
Thiago Delgado Pinto](https://github.com/thiagodp)
[π»](https://github.com/mattphillips/jest-extended/commits?author=thiagodp "Code") [π](https://github.com/mattphillips/jest-extended/commits?author=thiagodp "Documentation") [π‘](#example-thiagodp "Examples") [π€](#ideas-thiagodp "Ideas, Planning, & Feedback") [β οΈ](https://github.com/mattphillips/jest-extended/commits?author=thiagodp "Tests") |
## LICENSE
diff --git a/src/matchers/toBeDate/__snapshots__/index.test.js.snap b/src/matchers/toBeDate/__snapshots__/index.test.js.snap
new file mode 100644
index 00000000..b0f6d568
--- /dev/null
+++ b/src/matchers/toBeDate/__snapshots__/index.test.js.snap
@@ -0,0 +1,15 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`.not.toBeDate fails when given a date 1`] = `
+"expect(>received>).not.toBeDate(>)>
+
+Expected value to not be a date received:
+ 2018-01-01T13:00:00.000Z>"
+`;
+
+exports[`.toBeDate fails when not given a date 1`] = `
+"expect(>received>).toBeDate(>)>
+
+Expected value to be a date received:
+ false>"
+`;
diff --git a/src/matchers/toBeDate/index.js b/src/matchers/toBeDate/index.js
new file mode 100644
index 00000000..5e3af505
--- /dev/null
+++ b/src/matchers/toBeDate/index.js
@@ -0,0 +1,26 @@
+import { matcherHint, printReceived } from 'jest-matcher-utils';
+
+import predicate from './predicate';
+
+const passMessage = received => () =>
+ matcherHint('.not.toBeDate', 'received', '') +
+ '\n\n' +
+ 'Expected value to not be a date received:\n' +
+ ` ${printReceived(received)}`;
+
+const failMessage = received => () =>
+ matcherHint('.toBeDate', 'received', '') +
+ '\n\n' +
+ 'Expected value to be a date received:\n' +
+ ` ${printReceived(received)}`;
+
+export default {
+ toBeDate: expected => {
+ const pass = predicate(expected);
+ if (pass) {
+ return { pass: true, message: passMessage(expected) };
+ }
+
+ return { pass: false, message: failMessage(expected) };
+ }
+};
diff --git a/src/matchers/toBeDate/index.test.js b/src/matchers/toBeDate/index.test.js
new file mode 100644
index 00000000..19370a21
--- /dev/null
+++ b/src/matchers/toBeDate/index.test.js
@@ -0,0 +1,35 @@
+import each from 'jest-each';
+
+import matcher from './';
+
+expect.extend(matcher);
+
+describe('.toBeDate', () => {
+ test('passes when given a date', () => {
+ expect(new Date()).toBeDate();
+ });
+
+ test('fails when not given a date', () => {
+ expect(() => expect(false).toBeDate()).toThrowErrorMatchingSnapshot();
+ });
+});
+
+describe('.not.toBeDate', () => {
+ each([
+ [false],
+ [true],
+ [0],
+ [''],
+ [{}],
+ [() => {}],
+ [undefined],
+ [null],
+ [NaN]
+ ]).test('passes when not given a date: %s', given => {
+ expect(given).not.toBeDate();
+ });
+
+ test('fails when given a date', () => {
+ expect(() => expect(new Date('2018-01-01T13:00:00.000Z')).not.toBeDate()).toThrowErrorMatchingSnapshot();
+ });
+});
diff --git a/src/matchers/toBeDate/predicate.js b/src/matchers/toBeDate/predicate.js
new file mode 100644
index 00000000..fe0d79ee
--- /dev/null
+++ b/src/matchers/toBeDate/predicate.js
@@ -0,0 +1,11 @@
+function is(type) {
+ return value => Object.prototype.toString.call(value) === `[object ${type}]`;
+}
+
+let hasDateType = is('Date');
+
+function isDate(value) {
+ return hasDateType(value) && !isNaN(value);
+}
+
+export default expected => isDate(expected);
diff --git a/src/matchers/toBeDate/predicate.test.js b/src/matchers/toBeDate/predicate.test.js
new file mode 100644
index 00000000..1fcab069
--- /dev/null
+++ b/src/matchers/toBeDate/predicate.test.js
@@ -0,0 +1,15 @@
+import each from 'jest-each';
+import predicate from './predicate';
+
+describe('toBeDate Predicate', () => {
+ test('returns true when given a date', () => {
+ expect(predicate(new Date('12/25/2017'))).toBe(true);
+ });
+
+ each([[true], [false], [''], [0], [{}], [() => {}], [undefined], [null], [NaN]]).test(
+ 'returns false when given: %s',
+ given => {
+ expect(predicate(given)).toBe(false);
+ }
+ );
+});