Im using create-react-app and Im trying to write a test in jest for my action creator. One of the fields that the action adds is a random ID so I want to use expect.any(String) so that the test will pass. However I'm getting TypeError: expect.any is not a function
Here is my test:
describe('actions', () => {
it('should create an action to add a ticket', () => {
const payload = {
summary: 'A summary',
description: 'A description',
status:'open',
priority: 'minor',
};
const expected = {
type: actions.ADD_TICKET,
ticket: {
...payload,
id: expect.any(String),
},
};
const actual = addTicket(payload);
expect(actual).toEqual(expected)
})
})
expect.any was added in Jest 18 which wasnt shipping with this version of create-react-app. The version they just pushed now supports it
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