Skip to content Skip to sidebar Skip to footer

Jest: Spy On Object Method?

I need to spy on Date.toISOString() and return a value. const spy = jest.spyOn(global, Date); spies on Date global const spy = jest.spyOn(global, 'get', Date); spies on Date global

Solution 1:

Figured the solution:

const spy = jest.spyOn(global.Date.prototype, 'toISOString').mockImplementation(() => {
        return '123123123'
      })


Post a Comment for "Jest: Spy On Object Method?"