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>)
You can use expect.objectContaining which matches subset properties only. Above example can write as following:
expect(res.body).toMatchObject(expect.objectContaining({
  "property1": "value1"
  "property2": "value2"
}))
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With