Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete expect and jest-matcher-utils dependencies #332

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions CONTRIBUTING.md
Expand Up @@ -30,10 +30,6 @@ Head over to [here](https://hacktoberfest.digitalocean.com/sign_up/register) to
- `index.test.js` - Test suite that uses the new matcher and make sure it passes.
- `predicate.js` - The function that tests the actual value meets the expected value / behavior.
- `predicate.test.js` - Tests for the predicate both true/false cases must be covered.
- [`jest-matchers-utils`](https://github.com/facebook/jest/tree/master/packages/jest-matcher-utils) is being used for syntax highlighting of error messages.
- See the Jest docs for an [example usage](https://facebook.github.io/jest/docs/en/expect.html#thisutils)
- Jest's [`expect`](https://github.com/facebook/jest/tree/master/packages/expect) package is being used to access their deep `equals` function.
- `import { equals } from 'expect/build/jasmineUtils';`
- Docs for the new matcher should be updated in the API section of the `README.md` to no longer say `Unimplemented`.
- Type definitions for the new matchers should be added to `types/index.d.ts`.

Expand Down
4 changes: 1 addition & 3 deletions package.json
Expand Up @@ -54,10 +54,8 @@
"typescript": "^4.4.3"
},
"dependencies": {
"expect": "^26.6.2",
"jest-diff": "^27.2.5",
"jest-get-type": "^27.0.6",
"jest-matcher-utils": "^27.2.4"
"jest-get-type": "^27.0.6"
},
"engines": {
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
Expand Down
22 changes: 10 additions & 12 deletions src/matchers/toBeAfter/index.js
@@ -1,24 +1,22 @@
import { matcherHint, printReceived } from 'jest-matcher-utils';

import predicate from './predicate';

const passMessage = (received, after) => () =>
matcherHint('.not.toBeAfter', 'received', '') +
const passMessage = (utils, received, after) => () =>
utils.matcherHint('.not.toBeAfter', 'received', '') +
'\n\n' +
`Expected date to be after ${printReceived(after)} but received:\n` +
` ${printReceived(received)}`;
`Expected date to be after ${utils.printReceived(after)} but received:\n` +
` ${utils.printReceived(received)}`;

const failMessage = (received, after) => () =>
matcherHint('.toBeAfter', 'received', '') +
const failMessage = (utils, received, after) => () =>
utils.matcherHint('.toBeAfter', 'received', '') +
'\n\n' +
`Expected date to be after ${printReceived(after)} but received:\n` +
` ${printReceived(received)}`;
`Expected date to be after ${utils.printReceived(after)} but received:\n` +
` ${utils.printReceived(received)}`;

export function toBeAfter(date, after) {
const pass = predicate(date, after);
if (pass) {
return { pass: true, message: passMessage(date, after) };
return { pass: true, message: passMessage(this.utils, date, after) };
}

return { pass: false, message: failMessage(date, after) };
return { pass: false, message: failMessage(this.utils, date, after) };
}
22 changes: 10 additions & 12 deletions src/matchers/toBeAfterOrEqualTo/index.js
@@ -1,24 +1,22 @@
import { matcherHint, printReceived } from 'jest-matcher-utils';

import predicate from './predicate';

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

const failMessage = (received, before) => () =>
matcherHint('.toBeAfterOrEqualTo', 'received', '') +
const failMessage = (utils, received, before) => () =>
utils.matcherHint('.toBeAfterOrEqualTo', 'received', '') +
'\n\n' +
`Expected date to be after or equal to ${printReceived(before)} but received:\n` +
` ${printReceived(received)}`;
`Expected date to be after or equal to ${utils.printReceived(before)} but received:\n` +
` ${utils.printReceived(received)}`;

export function toBeAfterOrEqualTo(date, after) {
const pass = predicate(date, after);
if (pass) {
return { pass: true, message: passMessage(date, after) };
return { pass: true, message: passMessage(this.utils, date, after) };
}

return { pass: false, message: failMessage(date, after) };
return { pass: false, message: failMessage(this.utils, date, after) };
}
18 changes: 8 additions & 10 deletions src/matchers/toBeArray/index.js
@@ -1,24 +1,22 @@
import { matcherHint, printReceived } from 'jest-matcher-utils';

import predicate from './predicate';

const passMessage = received => () =>
matcherHint('.not.toBeArray', 'received', '') +
const passMessage = (utils, received) => () =>
utils.matcherHint('.not.toBeArray', 'received', '') +
'\n\n' +
'Expected value to not be an array received:\n' +
` ${printReceived(received)}`;
` ${utils.printReceived(received)}`;

const failMessage = received => () =>
matcherHint('.toBeArray', 'received', '') +
const failMessage = (utils, received) => () =>
utils.matcherHint('.toBeArray', 'received', '') +
'\n\n' +
'Expected value to be an array received:\n' +
` ${printReceived(received)}`;
` ${utils.printReceived(received)}`;

export function toBeArray(expected) {
const pass = predicate(expected);
if (pass) {
return { pass: true, message: passMessage(expected) };
return { pass: true, message: passMessage(this.utils, expected) };
}

return { pass: false, message: failMessage(expected) };
return { pass: false, message: failMessage(this.utils, expected) };
}
25 changes: 12 additions & 13 deletions src/matchers/toBeArrayOfSize/index.js
@@ -1,31 +1,30 @@
import { matcherHint, printExpected, printReceived } from 'jest-matcher-utils';
import { determinePropertyMessage } from '../../utils';

import predicate from './predicate';

const passMessage = (actual, expected) => () =>
`${matcherHint('.not.toBeArrayOfSize')}
const passMessage = (utils, actual, expected) => () =>
`${utils.matcherHint('.not.toBeArrayOfSize')}

Expected value to not be an array of size:
${printExpected(expected)}
${utils.printExpected(expected)}
Received:
value: ${printReceived(actual)}
length: ${printReceived(determinePropertyMessage(actual, 'length'))}`;
value: ${utils.printReceived(actual)}
length: ${utils.printReceived(determinePropertyMessage(actual, 'length'))}`;

const failMessage = (actual, expected) => () =>
`${matcherHint('.toBeArrayOfSize')}
const failMessage = (utils, actual, expected) => () =>
`${utils.matcherHint('.toBeArrayOfSize')}

Expected value to be an array of size:
${printExpected(expected)}
${utils.printExpected(expected)}
Received:
value: ${printReceived(actual)}
length: ${printReceived(determinePropertyMessage(actual, 'length'))}`;
value: ${utils.printReceived(actual)}
length: ${utils.printReceived(determinePropertyMessage(actual, 'length'))}`;

export function toBeArrayOfSize(actual, expected) {
const pass = predicate(actual, expected);
if (pass) {
return { pass: true, message: passMessage(actual, expected) };
return { pass: true, message: passMessage(this.utils, actual, expected) };
}

return { pass: false, message: failMessage(actual, expected) };
return { pass: false, message: failMessage(this.utils, actual, expected) };
}
22 changes: 10 additions & 12 deletions src/matchers/toBeBefore/index.js
@@ -1,24 +1,22 @@
import { matcherHint, printReceived } from 'jest-matcher-utils';

import predicate from './predicate';

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

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

export function toBeBefore(date, before) {
const pass = predicate(date, before);
if (pass) {
return { pass: true, message: passMessage(date, before) };
return { pass: true, message: passMessage(this.utils, date, before) };
}

return { pass: false, message: failMessage(date, before) };
return { pass: false, message: failMessage(this.utils, date, before) };
}
22 changes: 10 additions & 12 deletions src/matchers/toBeBeforeOrEqualTo/index.js
@@ -1,24 +1,22 @@
import { matcherHint, printReceived } from 'jest-matcher-utils';

import predicate from './predicate';

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

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

export function toBeBeforeOrEqualTo(date, before) {
const pass = predicate(date, before);
if (pass) {
return { pass: true, message: passMessage(date, before) };
return { pass: true, message: passMessage(this.utils, date, before) };
}

return { pass: false, message: failMessage(date, before) };
return { pass: false, message: failMessage(this.utils, date, before) };
}
22 changes: 10 additions & 12 deletions src/matchers/toBeBetween/index.js
@@ -1,24 +1,22 @@
import { matcherHint, printReceived } from 'jest-matcher-utils';

import predicate from './predicate';

const passMessage = (received, startDate, endDate) => () =>
matcherHint('.not.toBeBetween', 'received', '') +
const passMessage = (utils, received, startDate, endDate) => () =>
utils.matcherHint('.not.toBeBetween', 'received', '') +
'\n\n' +
`Expected date to be between ${printReceived(startDate)} and ${printReceived(endDate)} but received:\n` +
` ${printReceived(received)}`;
`Expected date to be between ${utils.printReceived(startDate)} and ${utils.printReceived(endDate)} but received:\n` +
` ${utils.printReceived(received)}`;

const failMessage = (received, startDate, endDate) => () =>
matcherHint('.toBeBetween', 'received', '') +
const failMessage = (utils, received, startDate, endDate) => () =>
utils.matcherHint('.toBeBetween', 'received', '') +
'\n\n' +
`Expected date to be between ${printReceived(startDate)} and ${printReceived(endDate)} but received:\n` +
` ${printReceived(received)}`;
`Expected date to be between ${utils.printReceived(startDate)} and ${utils.printReceived(endDate)} but received:\n` +
` ${utils.printReceived(received)}`;

export function toBeBetween(date, startDate, endDate) {
const pass = predicate(date, startDate, endDate);
if (pass) {
return { pass: true, message: passMessage(date, startDate, endDate) };
return { pass: true, message: passMessage(this.utils, date, startDate, endDate) };
}

return { pass: false, message: failMessage(date, startDate, endDate) };
return { pass: false, message: failMessage(this.utils, date, startDate, endDate) };
}
18 changes: 8 additions & 10 deletions src/matchers/toBeBoolean/index.js
@@ -1,24 +1,22 @@
import { matcherHint, printReceived } from 'jest-matcher-utils';

import predicate from './predicate';

const passMessage = received => () =>
matcherHint('.not.toBeBoolean', 'received', '') +
const passMessage = (utils, received) => () =>
utils.matcherHint('.not.toBeBoolean', 'received', '') +
'\n\n' +
'Expected value to not be of type boolean, received:\n' +
` ${printReceived(received)}`;
` ${utils.printReceived(received)}`;

const failMessage = received => () =>
matcherHint('.toBeBoolean', 'received', '') +
const failMessage = (utils, received) => () =>
utils.matcherHint('.toBeBoolean', 'received', '') +
'\n\n' +
'Expected value to be of type boolean, received:\n' +
` ${printReceived(received)}`;
` ${utils.printReceived(received)}`;

export function toBeBoolean(received) {
const pass = predicate(received);
if (pass) {
return { pass: true, message: passMessage(received) };
return { pass: true, message: passMessage(this.utils, received) };
}

return { pass: false, message: failMessage(received) };
return { pass: false, message: failMessage(this.utils, received) };
}
18 changes: 8 additions & 10 deletions src/matchers/toBeDate/index.js
@@ -1,24 +1,22 @@
import { matcherHint, printReceived } from 'jest-matcher-utils';

import predicate from './predicate';

const passMessage = received => () =>
matcherHint('.not.toBeDate', 'received', '') +
const passMessage = (utils, received) => () =>
utils.matcherHint('.not.toBeDate', 'received', '') +
'\n\n' +
'Expected value to not be a date received:\n' +
` ${printReceived(received)}`;
` ${utils.printReceived(received)}`;

const failMessage = received => () =>
matcherHint('.toBeDate', 'received', '') +
const failMessage = (utils, received) => () =>
utils.matcherHint('.toBeDate', 'received', '') +
'\n\n' +
'Expected value to be a date received:\n' +
` ${printReceived(received)}`;
` ${utils.printReceived(received)}`;

export function toBeDate(expected) {
const pass = predicate(expected);
if (pass) {
return { pass: true, message: passMessage(expected) };
return { pass: true, message: passMessage(this.utils, expected) };
}

return { pass: false, message: failMessage(expected) };
return { pass: false, message: failMessage(this.utils, expected) };
}
18 changes: 8 additions & 10 deletions src/matchers/toBeDateString/index.js
@@ -1,24 +1,22 @@
import { matcherHint, printReceived } from 'jest-matcher-utils';

import predicate from './predicate';

const passMessage = received => () =>
matcherHint('.not.toBeDateString', 'received', '') +
const passMessage = (utils, received) => () =>
utils.matcherHint('.not.toBeDateString', 'received', '') +
'\n\n' +
'Expected value to not be a date string received:\n' +
` ${printReceived(received)}`;
` ${utils.printReceived(received)}`;

const failMessage = received => () =>
matcherHint('.toBeDateString', 'received', '') +
const failMessage = (utils, received) => () =>
utils.matcherHint('.toBeDateString', 'received', '') +
'\n\n' +
'Expected value to be a date string received:\n' +
` ${printReceived(received)}`;
` ${utils.printReceived(received)}`;

export function toBeDateString(expected) {
const pass = predicate(expected);
if (pass) {
return { pass: true, message: passMessage(expected) };
return { pass: true, message: passMessage(this.utils, expected) };
}

return { pass: false, message: failMessage(expected) };
return { pass: false, message: failMessage(this.utils, expected) };
}