Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: expect.any is not a function

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)
 })
})
like image 920
unruffledBeaver Avatar asked Sep 17 '25 06:09

unruffledBeaver


1 Answers

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

like image 114
unruffledBeaver Avatar answered Sep 19 '25 23:09

unruffledBeaver