dayjs

Mocking dayjs extend

你说的曾经没有我的故事 提交于 2021-02-15 07:47:43
问题 In my code that needs testing I use import dayjs from 'dayjs'; import utc from 'dayjs/plugin/utc'; dayjs.extend(utc); dayjs().add(15, 'minute') In my test I need to mock dayjs in order to always have the same date when comparing snapshots in jest so I did jest.mock('dayjs', () => jest.fn((...args) => jest.requireActual('dayjs')( args.filter((arg) => arg).length > 0 ? args : '2020-08-12' ) ) ); It fails with TypeError: _dayjs.default.extend is not a function Unfortunately similar questions on

Mocking dayjs extend

巧了我就是萌 提交于 2021-02-15 07:47:11
问题 In my code that needs testing I use import dayjs from 'dayjs'; import utc from 'dayjs/plugin/utc'; dayjs.extend(utc); dayjs().add(15, 'minute') In my test I need to mock dayjs in order to always have the same date when comparing snapshots in jest so I did jest.mock('dayjs', () => jest.fn((...args) => jest.requireActual('dayjs')( args.filter((arg) => arg).length > 0 ? args : '2020-08-12' ) ) ); It fails with TypeError: _dayjs.default.extend is not a function Unfortunately similar questions on