Skip to content

Commit

Permalink
fix: replace toEqual with toMatchObject for resp bodies (#478)
Browse files Browse the repository at this point in the history
Signed-off-by: hxtree <[email protected]>
  • Loading branch information
hxtree authored Oct 29, 2023
1 parent 1359c1c commit 245a97e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ describe('/auth', () => {
.post('/auth/login')
.send(body)
.expect(201);
expect(response.body).toEqual(

expect(response.body).toMatchObject(
expect.objectContaining({
token: expect.any(String),
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('/affiliations', () => {
.get(`/affiliations/${characterSheet._id}`)
.expect(200);

expect(response.body).toEqual(characterSheet.affiliation);
expect(response.body).toMatchObject(characterSheet.affiliation);
});

it('/POST /affiliations/:id', async () => {
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('/affiliations', () => {
.send(body)
.expect(201);

expect(response.body).toEqual({
expect(response.body).toMatchObject({
acknowledged: true,
matchedCount: 1,
modifiedCount: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ describe('/character-sheets', () => {
const response = await supertest(app.getHttpServer())
.get(`/character-sheets/${v4()}`)
.expect(404);
expect(response.body).toEqual({ message: 'Not Found', statusCode: 404 });
expect(response.body).toMatchObject({
message: 'Not Found',
statusCode: 404,
});
});

it('should find result if exists', async () => {
Expand All @@ -74,7 +77,7 @@ describe('/character-sheets', () => {
.get(`/character-sheets/${characterSheet._id}`)
.expect(200);

expect(result.body).toEqual(
expect(result.body).toMatchObject(
expect.objectContaining({
id: characterSheet._id,
instanceId: characterSheet.instanceId,
Expand All @@ -94,7 +97,7 @@ describe('/character-sheets', () => {
const response = await supertest(app.getHttpServer())
.get('/character-sheets/?name=MEEKU_ONI')
.expect(200);
expect(response.body).toEqual([]);
expect(response.body).toMatchObject([]);
});

it('should find result if exists', async () => {
Expand All @@ -109,7 +112,7 @@ describe('/character-sheets', () => {
.get('/character-sheets/?name=JANE')
.expect(200);

expect(result.body[0]).toEqual(
expect(result.body[0]).toMatchObject(
expect.objectContaining({
id: characterSheet._id,
instanceId: characterSheet.instanceId,
Expand All @@ -134,7 +137,7 @@ describe('/character-sheets', () => {
.delete(`/character-sheets/${characterSheet._id}`)
.expect(200);

expect(result.body).toEqual(
expect(result.body).toMatchObject(
expect.objectContaining({
deleted: true,
deletedCount: 1,
Expand Down
2 changes: 1 addition & 1 deletion services/character-sheet/src/modules/npc/npc.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('/spawns', () => {
.send(body)
.expect(201);

expect(result.body).toEqual(
expect(result.body).toMatchObject(
expect.objectContaining({
id: body.id,
instanceId: body.instanceId,
Expand Down
14 changes: 7 additions & 7 deletions services/html-to-pdf/src/module/pdf/pdf.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('/pdf', () => {
.expect(200);

expect(response.header['content-type']).toEqual('application/pdf');
expect(response.body).toEqual(Buffer.from('Test', 'utf-8'));
expect(response.body).toMatchObject(Buffer.from('Test', 'utf-8'));
});
});

Expand All @@ -58,7 +58,7 @@ describe('/pdf', () => {
.expect(201);

expect(response.header['content-type']).toEqual('application/pdf');
expect(response.body).toEqual(Buffer.from('Test', 'utf-8'));
expect(response.body).toMatchObject(Buffer.from('Test', 'utf-8'));
});

it('should render url page to json', async () => {
Expand All @@ -78,7 +78,7 @@ describe('/pdf', () => {
expect(response.header['content-type']).toEqual(
'application/json; charset=utf-8',
);
expect(response.body).toEqual(
expect(response.body).toMatchObject(
expect.objectContaining({
content: 'VGVzdA==',
filename: expect.stringContaining('.pdf'),
Expand All @@ -104,7 +104,7 @@ describe('/pdf', () => {
expect(response.header['content-type']).toEqual(
'application/json; charset=utf-8',
);
expect(response.body).toEqual(
expect(response.body).toMatchObject(
expect.objectContaining({
title: 'Example Domain',
}),
Expand All @@ -127,7 +127,7 @@ describe('/pdf', () => {
.expect(201);

expect(response.header['content-type']).toEqual('application/pdf');
expect(response.body).toEqual(Buffer.from('Test', 'utf-8'));
expect(response.body).toMatchObject(Buffer.from('Test', 'utf-8'));
});

it('should render url page to json', async () => {
Expand All @@ -148,7 +148,7 @@ describe('/pdf', () => {
expect(response.header['content-type']).toEqual(
'application/json; charset=utf-8',
);
expect(response.body).toEqual(
expect(response.body).toMatchObject(
expect.objectContaining({
content: 'VGVzdA==',
filename: expect.stringContaining('.pdf'),
Expand All @@ -175,7 +175,7 @@ describe('/pdf', () => {
expect(response.header['content-type']).toEqual(
'application/json; charset=utf-8',
);
expect(response.body).toEqual(
expect(response.body).toMatchObject(
expect.objectContaining({
title: 'Example Page',
}),
Expand Down

0 comments on commit 245a97e

Please sign in to comment.