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

fix: rename toHaveBodyEqualsTo to toHaveBodyEquals #32

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Additional expect matchers for http clients (e.g. Axios), supports `jest`, `vite
- [.toHaveInsufficientStorageStatus()](#tohaveinsufficientstoragestatus)
- [.toHaveNetworkAuthenticationRequiredStatus()](#tohavenetworkauthenticationrequiredstatus)
- [.toHaveHeader(`<header name>`[, `<header value>`])](#tohaveheaderheader-name-header-value)
- [.toHaveBodyEqualsTo(`<body>`)](#tohavebodyequalstobody)
- [.toHaveBodyEquals(`<body>`)](#tohavebodyequalsbody)


## Installation
Expand Down Expand Up @@ -1353,19 +1353,19 @@ test('passes when using .toHaveHeader() with expected value', async () => {
});
```

#### .toHaveBodyEqualsTo(`<body>`)
#### .toHaveBodyEquals(`<body>`)

Use `.toHaveBodyEqualsTo` when checking if response body is equal to the expected body
Use `.toHaveBodyEquals` when checking if response body is equal to the expected body

```js
test('passes when response body match the expected body', async () => {
const response = await axios.get('https://httpstat.us/200');
expect(response).toHaveBodyEqualsTo('200 OK');
expect(response).toHaveBodyEquals('200 OK');
});

test('passes when using .not.toHaveBodyEqualsTo() with different body', async () => {
test('passes when using .not.toHaveBodyEquals() with different body', async () => {
const response = await axios.get('https://httpstat.us/200');
expect(response).not.toHaveBodyEqualsTo('404 NOT FOUND');
expect(response).not.toHaveBodyEquals('404 NOT FOUND');
});
```

Expand Down
4 changes: 2 additions & 2 deletions src/matchers/data/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { toHaveBodyEqualsTo } = require('./toHaveBodyEqualsTo');
const { toHaveBodyEquals } = require('./toHaveBodyEquals');

module.exports = {
toHaveBodyEqualsTo,
toHaveBodyEquals,
};
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function getJSONBody(adapter) {
/**
* @this {import('expect').MatcherUtils}
*/
function toHaveBodyEqualsTo(actual, expectedValue) {
function toHaveBodyEquals(actual, expectedValue) {
const { matcherHint, printExpected, printDiffOrStringify, printReceived } = this.utils;

const adapter = getMatchingAdapter(actual);
Expand Down Expand Up @@ -78,4 +78,4 @@ function toHaveBodyEqualsTo(actual, expectedValue) {
};
}

module.exports = { toHaveBodyEqualsTo };
module.exports = { toHaveBodyEquals };
66 changes: 33 additions & 33 deletions test/matchers/data/toHaveBodyEqualsTo.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const { toHaveBodyEqualsTo } = require('../../../src');
const { toHaveBodyEquals } = require('../../../src');
const { describe, before, it } = require('node:test');
const { buildServer } = require('../../helpers/server-helper.js');
const { expect, JestAssertionError } = require('expect');
const { getServerUrl } = require('../../helpers/server-helper');
const { testClients } = require('../../helpers/supported-clients');

expect.extend({ toHaveBodyEqualsTo });
expect.extend({ toHaveBodyEquals });

describe('(.not).toHaveBodyEqualsTo', () => {
describe('(.not).toHaveBodyEquals', () => {
let apiUrl = getServerUrl();

before(async () => {
Expand All @@ -16,7 +16,7 @@ describe('(.not).toHaveBodyEqualsTo', () => {

for (const testClient of testClients) {
describe(`using ${testClient.name}`, () => {
describe('.toHaveBodyEqualsTo', () => {
describe('.toHaveBodyEquals', () => {
it('should pass when the expected data match and body is json', async () => {
const response = await testClient.post(`${apiUrl}/body`, {
contentType: 'application/json',
Expand All @@ -31,7 +31,7 @@ describe('(.not).toHaveBodyEqualsTo', () => {
},
});

expect(response).toHaveBodyEqualsTo({
expect(response).toHaveBodyEquals({
a: '1',
b: 2,
c: true,
Expand All @@ -42,7 +42,7 @@ describe('(.not).toHaveBodyEqualsTo', () => {
});

expect({ response }).toEqual({
response: expect.toHaveBodyEqualsTo({
response: expect.toHaveBodyEquals({
a: '1',
b: 2,
c: true,
Expand All @@ -60,10 +60,10 @@ describe('(.not).toHaveBodyEqualsTo', () => {
data: 'Hello World',
});

expect(response).toHaveBodyEqualsTo('Hello World');
expect(response).toHaveBodyEquals('Hello World');

expect({ response }).toEqual({
response: expect.toHaveBodyEqualsTo('Hello World'),
response: expect.toHaveBodyEquals('Hello World'),
});
});

Expand All @@ -81,15 +81,15 @@ describe('(.not).toHaveBodyEqualsTo', () => {
},
});

expect(response).toHaveBodyEqualsTo(
expect(response).toHaveBodyEquals(
expect.objectContaining({
b: expect.any(Number),
c: true,
}),
);

expect({ response }).toEqual({
response: expect.toHaveBodyEqualsTo(
response: expect.toHaveBodyEquals(
expect.objectContaining({
b: expect.any(Number),
c: true,
Expand All @@ -110,7 +110,7 @@ describe('(.not).toHaveBodyEqualsTo', () => {
});

try {
expect(response).toHaveBodyEqualsTo({
expect(response).toHaveBodyEquals({
a: '1',
b: 2,
c: true,
Expand All @@ -125,7 +125,7 @@ describe('(.not).toHaveBodyEqualsTo', () => {

expect(() =>
expect({ response }).toEqual({
response: expect.toHaveBodyEqualsTo({
response: expect.toHaveBodyEquals({
a: '1',
b: 2,
c: true,
Expand All @@ -148,14 +148,14 @@ describe('(.not).toHaveBodyEqualsTo', () => {
});

try {
expect(response).toHaveBodyEqualsTo('Someone');
expect(response).toHaveBodyEquals('Someone');
} catch (e) {
t.assert.snapshot(e);
}

expect(() =>
expect({ response }).toEqual({
response: expect.toHaveBodyEqualsTo('Someone'),
response: expect.toHaveBodyEquals('Someone'),
}),
).toThrowError(JestAssertionError);
});
Expand All @@ -178,7 +178,7 @@ describe('(.not).toHaveBodyEqualsTo', () => {
});

try {
expect(response).toHaveBodyEqualsTo(
expect(response).toHaveBodyEquals(
expect.objectContaining({
a: expect.any(Number),
}),
Expand All @@ -189,7 +189,7 @@ describe('(.not).toHaveBodyEqualsTo', () => {

expect(() =>
expect({ response }).toEqual({
response: expect.toHaveBodyEqualsTo(
response: expect.toHaveBodyEquals(
expect.objectContaining({
a: expect.any(Number),
}),
Expand All @@ -210,20 +210,20 @@ describe('(.not).toHaveBodyEqualsTo', () => {
});

try {
expect(response).toHaveBodyEqualsTo('Hello World');
expect(response).toHaveBodyEquals('Hello World');
} catch (e) {
t.assert.snapshot(e);
}

expect(() =>
expect({ response }).toEqual({
response: expect.toHaveBodyEqualsTo('Hello World'),
response: expect.toHaveBodyEquals('Hello World'),
}),
).toThrowError(JestAssertionError);
});
});

describe('.not.toHaveBodyEqualsTo', () => {
describe('.not.toHaveBodyEquals', () => {
it('should pass when the json data does not match', async () => {
const response = await testClient.post(`${apiUrl}/body`, {
contentType: 'application/json',
Expand All @@ -232,7 +232,7 @@ describe('(.not).toHaveBodyEqualsTo', () => {
},
});

expect(response).not.toHaveBodyEqualsTo({
expect(response).not.toHaveBodyEquals({
a: '1',
b: 2,
c: true,
Expand All @@ -243,7 +243,7 @@ describe('(.not).toHaveBodyEqualsTo', () => {
});

expect({ response }).toEqual({
response: expect.not.toHaveBodyEqualsTo({
response: expect.not.toHaveBodyEquals({
a: '1',
b: 2,
c: true,
Expand All @@ -261,10 +261,10 @@ describe('(.not).toHaveBodyEqualsTo', () => {
data: 'Hello World',
});

expect(response).not.toHaveBodyEqualsTo('Someone');
expect(response).not.toHaveBodyEquals('Someone');

expect({ response }).toEqual({
response: expect.not.toHaveBodyEqualsTo('Someone'),
response: expect.not.toHaveBodyEquals('Someone'),
});
});

Expand All @@ -282,14 +282,14 @@ describe('(.not).toHaveBodyEqualsTo', () => {
},
});

expect(response).not.toHaveBodyEqualsTo(
expect(response).not.toHaveBodyEquals(
expect.objectContaining({
a: expect.any(Number),
}),
);

expect({ response }).toEqual({
response: expect.not.toHaveBodyEqualsTo(
response: expect.not.toHaveBodyEquals(
expect.objectContaining({
a: expect.any(Number),
}),
Expand All @@ -305,9 +305,9 @@ describe('(.not).toHaveBodyEqualsTo', () => {
},
});

expect(response).not.toHaveBodyEqualsTo('Hello World');
expect(response).not.toHaveBodyEquals('Hello World');
expect({ response }).toEqual({
response: expect.not.toHaveBodyEqualsTo('Hello World'),
response: expect.not.toHaveBodyEquals('Hello World'),
});
});

Expand All @@ -329,7 +329,7 @@ describe('(.not).toHaveBodyEqualsTo', () => {
});

try {
expect(response).not.toHaveBodyEqualsTo({
expect(response).not.toHaveBodyEquals({
a: '1',
b: 2,
c: true,
Expand All @@ -344,7 +344,7 @@ describe('(.not).toHaveBodyEqualsTo', () => {

expect(() =>
expect({ response }).toEqual({
response: expect.not.toHaveBodyEqualsTo({
response: expect.not.toHaveBodyEquals({
a: '1',
b: 2,
c: true,
Expand All @@ -367,14 +367,14 @@ describe('(.not).toHaveBodyEqualsTo', () => {
});

try {
expect(response).not.toHaveBodyEqualsTo('Hello World');
expect(response).not.toHaveBodyEquals('Hello World');
} catch (e) {
t.assert.snapshot(e);
}

expect(() =>
expect({ response }).toEqual({
response: expect.not.toHaveBodyEqualsTo('Hello World'),
response: expect.not.toHaveBodyEquals('Hello World'),
}),
).toThrowError(JestAssertionError);
});
Expand All @@ -397,7 +397,7 @@ describe('(.not).toHaveBodyEqualsTo', () => {
});

try {
expect(response).not.toHaveBodyEqualsTo(
expect(response).not.toHaveBodyEquals(
expect.objectContaining({
b: expect.any(Number),
c: true,
Expand All @@ -409,7 +409,7 @@ describe('(.not).toHaveBodyEqualsTo', () => {

expect(() =>
expect({ response }).toEqual({
response: expect.not.toHaveBodyEqualsTo(
response: expect.not.toHaveBodyEquals(
expect.objectContaining({
b: expect.any(Number),
c: true,
Expand Down
14 changes: 7 additions & 7 deletions test/matchers/data/toHaveBodyEqualsTo.test.js.snapshot
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
exports[`(.not).toHaveBodyEqualsTo > using axios > .not.toHaveBodyEqualsTo > should fail when the expected data match and body is json 1`] = `
exports[`(.not).toHaveBodyEquals > using axios > .not.toHaveBodyEquals > should fail when the expected data match and body is json 1`] = `
<dim>expect(</intensity><red>received</color><dim>).not.toHaveDataEqualsTo(</intensity><green>expected</color><dim>)</intensity>

Expected request to not have data:
Expand All @@ -19,7 +19,7 @@ response is:
}
`;

exports[`(.not).toHaveBodyEqualsTo > using axios > .not.toHaveBodyEqualsTo > should fail when the expected data match and body is json when using asymmetric matchers in the data 1`] = `
exports[`(.not).toHaveBodyEquals > using axios > .not.toHaveBodyEquals > should fail when the expected data match and body is json when using asymmetric matchers in the data 1`] = `
<dim>expect(</intensity><red>received</color><dim>).not.toHaveDataEqualsTo(</intensity><green>expected</color><dim>)</intensity>

Expected request to not have data:
Expand All @@ -40,7 +40,7 @@ response is:
}
`;

exports[`(.not).toHaveBodyEqualsTo > using axios > .not.toHaveBodyEqualsTo > should fail when the expected data match and body is text 1`] = `
exports[`(.not).toHaveBodyEquals > using axios > .not.toHaveBodyEquals > should fail when the expected data match and body is text 1`] = `
<dim>expect(</intensity><red>received</color><dim>).not.toHaveDataEqualsTo(</intensity><green>expected</color><dim>)</intensity>

Expected request to not have data:
Expand All @@ -61,7 +61,7 @@ response is:
}
`;

exports[`(.not).toHaveBodyEqualsTo > using axios > .toHaveBodyEqualsTo > should fail when the json data does not match 1`] = `
exports[`(.not).toHaveBodyEquals > using axios > .toHaveBodyEquals > should fail when the json data does not match 1`] = `
<dim>expect(</intensity><red>received</color><dim>).toHaveDataEqualsTo(</intensity><green>expected</color><dim>)</intensity>

Expected request to have data:
Expand Down Expand Up @@ -92,7 +92,7 @@ response is:
}
`;

exports[`(.not).toHaveBodyEqualsTo > using axios > .toHaveBodyEqualsTo > should fail when the json data does not match when using asymmetric matchers in the data 1`] = `
exports[`(.not).toHaveBodyEquals > using axios > .toHaveBodyEquals > should fail when the json data does not match when using asymmetric matchers in the data 1`] = `
<dim>expect(</intensity><red>received</color><dim>).toHaveDataEqualsTo(</intensity><green>expected</color><dim>)</intensity>

Expected request to have data:
Expand Down Expand Up @@ -124,7 +124,7 @@ response is:
}
`;

exports[`(.not).toHaveBodyEqualsTo > using axios > .toHaveBodyEqualsTo > should fail when the response body type does not match 1`] = `
exports[`(.not).toHaveBodyEquals > using axios > .toHaveBodyEquals > should fail when the response body type does not match 1`] = `
<dim>expect(</intensity><red>received</color><dim>).toHaveDataEqualsTo(</intensity><green>expected</color><dim>)</intensity>

Expected request to have data:
Expand All @@ -144,7 +144,7 @@ response is:
}
`;

exports[`(.not).toHaveBodyEqualsTo > using axios > .toHaveBodyEqualsTo > should fail when the text data does not match 1`] = `
exports[`(.not).toHaveBodyEquals > using axios > .toHaveBodyEquals > should fail when the text data does not match 1`] = `
<dim>expect(</intensity><red>received</color><dim>).toHaveDataEqualsTo(</intensity><green>expected</color><dim>)</intensity>

Expected request to have data:
Expand Down
Loading
Loading