Jest'te test etmeye çalıştığım aşağıdaki modüle sahibim:
// myModule.js
export function otherFn() {
console.log('do something');
}
export function testFn() {
otherFn();
// do other things
}
Yukarıda gösterildiği gibi, bazı adlandırılmış işlevleri dışa aktarır ve önemli ölçüde testFnkullanır otherFn.
Jest'te birim testimi yazarken testFn, otherFnişlevle dalga geçmek istiyorum çünkü otherFnbirim testimi etkilemek için hataların olmasını istemiyorum testFn. Sorunum, bunu yapmanın en iyi yolunun ne olduğundan emin değilim:
// 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()
});
});
Herhangi bir yardım / anlayış takdir edilmektedir.
otherFnayrı bir modüle çıkarmanız ve bununla dalga geçmeniz gerekir .