-
-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Labels
Description
Description
I have a case when the field can be present or not in the object. I would like to check the field if it's present in the object
Case 1: { a: 10, b: 'qwerty' }
Case 2: { a: 10, b: 'qwerty' , c: 10}
(this won't work)
expect({ a: 10, b: 'qwerty' }).toMatchObject({
a: expect.toBePositiveNumber(),
b: expect.toBeNonEmptyString(),
c: expect.toBeOptionalOf(expect.toBeNumber()),
})Returns error:
Expected: {"a": toBePositiveNumber<>, "b": toBeNonEmptyString<>, "c": toBeOptionalOf<toBeNumber>}
Received: {"a": 10, "b": "qwerty"}
Maybe there is a way to check optional field?