This question is the general case for Include toBeCloseTo in Jest .toMatchObject.
How can I use any Jest extend matcher within the .toMatchObject(object)
matcher?
For example, testing that an object has several fields, including a field foo
> zero:
expect({ a: 'b', c: 'd', foo: 3 }).toMatchObject({
a: 'b',
c: 'd',
foo: expect.toBeGreaterThan(0), // expect.toBeGreaterThan is not a function
});
I know I could write expect(theObject.foo).toBeGreaterThan(0)
, but is there away to not break away the logic for testing .foo
from the .toMatchObject
call?