mardi 19 janvier 2021

how to pass expect.toMatchObject() with Date as one of the expected property value using jest?

I have an express API endpoint which returns an object and on that object there is a property(property3 in our example below) which has a date as it's value.

For e.g

  res.body = {
       "property1": "value1"
       "property2": "value2"
       "property3": new Date()
    }

I am performing test on this endpoint using jest and supertest.

Since date.now() !== date.now(), how will i pass

expect(res.body).toMatchObject(<expectedObject>)

Aucun commentaire:

Enregistrer un commentaire