IssueRaiser

"Received: serializes to the same string" on object equality checking

## 🐛 Bug Report Using `.toMatchObject()` returns failing test with message ` Received: serializes to the same string` ![image](https://user-images.githubusercontent.com/4678102/58015463-e78c7f00-7b2d-11e9-9f4e-038625c0c623.png) ## To Reproduce I am trying to check the `users` object I receive against my `expectedUsers`. The received object coming back from MongoDB contains the fields `"__v"` and `"_id"` which I do not want to check for (they always change for every test). As such, I am using `.toMatchObject()` and cannot use something else like `.toEqual()`. My test snippet is below: ``` test("should show all existing users", async () => { const expectedUsers = [ { email: "andy@example.com", friends: [], followers: [], following: [], blocked: [] }, { email: "john@example.com", friends: ["andy@example.com", "mary@example.com"], followers: [], following: [], blocked: [] }, { email: "mary@example.com", friends: [], followers: [], following: [], blocked: ["john@example.com"] } ]; await request(app) .get(route(path)) .expect("Content-Type", /json/) .expect(200); const users = await User.find(); expect(users).toMatchObject(expectedUsers); }); ``` (`request` is made with `supertest`) ## Expected behavior As documented [here](https://jestjs.io/docs/en/expect.html#tomatchobjectobject), > Use .toMatchObject to check that a JavaScript obje

Posted by sabriele on May 20, 2019, 10:44 AM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.4,000 issues0 comments

github (SaaS)

"Received: serializes to the same string" on object equality checking

sabrieleMay 20, 2019, 10:44 AM

## 🐛 Bug Report Using `.toMatchObject()` returns failing test with message ` Received: serializes to the same string` ![image](https://user-images.githubusercontent.com/4678102/58015463-e78c7f00-7b2d-11e9-9f4e-038625c0c623.png) ## To Reproduce I am trying to check the `users` object I receive against my `expectedUsers`. The received object coming back from MongoDB contains the fields `"__v"` and `"_id"` which I do not want to check for (they always change for every test). As such, I am using `.toMatchObject()` and cannot use something else like `.toEqual()`. My test snippet is below: ``` test("should show all existing users", async () => { const expectedUsers = [ { email: "andy@example.com", friends: [], followers: [], following: [], blocked: [] }, { email: "john@example.com", friends: ["andy@example.com", "mary@example.com"], followers: [], following: [], blocked: [] }, { email: "mary@example.com", friends: [], followers: [], following: [], blocked: ["john@example.com"] } ]; await request(app) .get(route(path)) .expect("Content-Type", /json/) .expect(200); const users = await User.find(); expect(users).toMatchObject(expectedUsers); }); ``` (`request` is made with `supertest`) ## Expected behavior As documented [here](https://jestjs.io/docs/en/expect.html#tomatchobjectobject), > Use .toMatchObject to check that a JavaScript obje

Comments (0)

No comments yet. Start the discussion.

Comment on this issue