Monday, 18 November 2019

Passing expression to Jest.unmock

I am implementing a utility function that will ease calling jest.unmock multiple times

it turns out jest.unmock only expects string literal


jest.unmock('got')   // works

const mod = 'got'
jest.unmock(mod)   // does not work

I tried using eval like the following But it doesn't work

const mod = "'got'"
eval(`jest.unmock(${mod})`)

Is there any work round to do this?

What is the rationale behind this?



from Passing expression to Jest.unmock

No comments:

Post a Comment