Skip to content

Commit

Permalink
Condense toBeBefore matcher into one file
Browse files Browse the repository at this point in the history
  • Loading branch information
mattphillips committed Jan 31, 2022
1 parent 83edb9b commit 0614907
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 46 deletions.
19 changes: 19 additions & 0 deletions src/matchers/toBeBefore.js
@@ -0,0 +1,19 @@
export function toBeBefore(actual, expected) {
const { matcherHint, printReceived } = this.utils;
const passMessage = () =>
matcherHint('.not.toBeBefore', 'received', '') +
'\n\n' +
`Expected date to be before ${printReceived(actual)} but received:\n` +
` ${printReceived(expected)}`;

const failMessage = () =>
matcherHint('.toBeBefore', 'received', '') +
'\n\n' +
`Expected date to be before ${printReceived(actual)} but received:\n` +
` ${printReceived(expected)}`;

const pass = actual < expected;
const message = pass ? passMessage : failMessage;

return { pass, message };
}
22 changes: 0 additions & 22 deletions src/matchers/toBeBefore/index.js

This file was deleted.

5 changes: 0 additions & 5 deletions src/matchers/toBeBefore/predicate.js

This file was deleted.

14 changes: 0 additions & 14 deletions src/matchers/toBeBefore/predicate.test.js

This file was deleted.

Expand Up @@ -3,13 +3,13 @@
exports[`.not.toBeBefore fails when given an earlier date 1`] = `
"<dim>expect(</><red>received</><dim>).not.toBeBefore()</>
Expected date to be before <red>2018-06-02T22:00:00.000Z</> but received:
<red>2018-06-01T22:00:00.000Z</>"
Expected date to be before <red>2018-06-01T22:00:00.000Z</> but received:
<red>2018-06-02T22:00:00.000Z</>"
`;
exports[`.toBeBefore fails when given a later date 1`] = `
"<dim>expect(</><red>received</><dim>).toBeBefore()</>
Expected date to be before <red>2018-06-01T22:00:00.000Z</> but received:
<red>2018-06-02T22:00:00.000Z</>"
Expected date to be before <red>2018-06-02T22:00:00.000Z</> but received:
<red>2018-06-01T22:00:00.000Z</>"
`;
@@ -1,4 +1,4 @@
import * as matcher from './';
import * as matcher from 'src/matchers/toBeBefore';

expect.extend(matcher);

Expand Down

0 comments on commit 0614907

Please sign in to comment.