I am trying to use expect.toMatchObject to test an object where some of the properties are variable. As far as I can tell from the docs this should work, but something is going wrong.
it('should create user new user', async () => {
expect({
username: 'giodamelio',
password: 'hunter2',
id: 10,
createdAt: Date.now(),
updatedAt: Date.now(),
}).toMatchObject({
id: expect.any(Number),
username: 'giodamelio',
password: 'hunter2',
createdAt: expect.any(Date),
updatedAt: expect.any(Date),
});
});
When I run that I get this error.
FAIL test/models/user.test.js
● should create user new user
expect(received).toMatchObject(expected)
Expected value to match object:
{"createdAt": Any<Date>, "id": Any<Number>, "password": "hunter2", "updatedAt": Any<Date>, "username": "giodamelio"}
Received:
{"createdAt": 1499463578254, "id": 10, "password": "hunter2", "updatedAt": 1499463578254, "username": "giodamelio"}
Difference:
- Expected
+ Received
Object {
- "createdAt": Any<Date>,
- "id": Any<Number>,
+ "createdAt": 1499463578254,
+ "id": 10,
"password": "hunter2",
- "updatedAt": Any<Date>,
+ "updatedAt": 1499463578254,
"username": "giodamelio",
}
Aucun commentaire:
Enregistrer un commentaire