Skip to content

Commit

Permalink
Condense toBeBeforeOrEqualTo 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 0614907 commit 7408597
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 50 deletions.
20 changes: 20 additions & 0 deletions src/matchers/toBeBeforeOrEqualTo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export function toBeBeforeOrEqualTo(actual, expected) {
const { matcherHint, printReceived } = this.utils;

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

const failMessage = () =>
matcherHint('.toBeBeforeOrEqualTo', 'received', '') +
'\n\n' +
`Expected date to be before or equal to ${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/toBeBeforeOrEqualTo/index.js

This file was deleted.

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

This file was deleted.

18 changes: 0 additions & 18 deletions src/matchers/toBeBeforeOrEqualTo/predicate.test.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
exports[`.not.toBeBeforeOrEqualTo fails when given an earlier date 1`] = `
"<dim>expect(</><red>received</><dim>).not.toBeBeforeOrEqualTo()</>
Expected date to be before or equal to <red>2019-09-10T22:00:00.000Z</> but received:
<red>2019-09-01T22:00:00.000Z</>"
Expected date to be before or equal to <red>2019-09-01T22:00:00.000Z</> but received:
<red>2019-09-10T22:00:00.000Z</>"
`;
exports[`.not.toBeBeforeOrEqualTo fails when given an equal date 1`] = `
Expand All @@ -17,6 +17,6 @@ Expected date to be before or equal to <red>2019-09-01T22:00:00.000Z</> but rece
exports[`.toBeBeforeOrEqualTo fails when given a later date 1`] = `
"<dim>expect(</><red>received</><dim>).toBeBeforeOrEqualTo()</>
Expected date to be before or equal to <red>2019-09-01T22:00:00.000Z</> but received:
<red>2019-09-10T22:00:00.000Z</>"
Expected date to be before or equal to <red>2019-09-10T22:00:00.000Z</> but received:
<red>2019-09-01T22:00:00.000Z</>"
`;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as matcher from './';
import * as matcher from 'src/matchers/toBeBeforeOrEqualTo';

expect.extend(matcher);

Expand Down

0 comments on commit 7408597

Please sign in to comment.