Como zombar da função nomeada importada no Jest quando o módulo é desbloqueado
Eu tenho o seguinte módulo que estou tentando testar no Jest:
// myModule.js
export function otherFn() {
console.log('do something');
}
export function testFn() {
otherFn();
// do other things
}
Como mostrado acima, ele exporta algumas funções nomeadas e importantetestFn
usaotherFn
.
Em Jest, quando estou escrevendo meu teste de unidade paratestFn
, Quero zombar dootherFn
função porque eu não quero erros nootherFn
afetar meu teste de unidadetestFn
. Meu problema é que não tenho certeza da melhor maneira de fazer isso:
// myModule.test.js
jest.unmock('myModule');
import { testFn, otherFn } from 'myModule';
describe('test category', () => {
it('tests something about testFn', () => {
// I want to mock "otherFn" here but can't reassign
// a.k.a. can't do otherFn = jest.fn()
});
});
Qualquer ajuda / insight é apreciada.