Reputation: 12520
I want to test that an object returned matches what I expect with jest
.
I'm trying this:
const desiredResult = {
host: '192.168.1.1',
port: expect.any(Number),
delta: expect.toBeDefined()
}
expect(result).toMatchObject(desiredResult)
jest
is saying that .toBeDefined()
is not a function (but is fine with .any(Number)
:
TypeError: expect.toBeDefined is not a function
173 | host: '192.168.1.1',
174 | port: expect.any(Number),
> 175 | delta: expect.toBeDefined()
| ^
176 | }
177 | expect(portCallback.mock.calls[0][0]).toMatchObject(desiredResult)
ect(desiredResult)
Upvotes: 2
Views: 3540
Reputation: 9326
Use expect.anything()
instead of expect.toBeDefined()
.
It is like expect.any()
, but does not require constructor as paramater and matches anything but null
or undefined
.
Please see https://facebook.github.io/jest/docs/en/expect.html#expectanything
Upvotes: 1