मैं एक जेएस का परीक्षण करना चाहता हूं जो डेटा लाने के लिए एक तीसरे lib का उपयोग कर रहा है, इसलिए मैं कार्यान्वयन के लिए जेस्ट मॉक का उपयोग कर रहा हूं। यह काम कर रहा है जब मैं इसे सीधे परीक्षण में बुलाता हूं। हालांकि, यह स्रोत कोड में उपयोग होने पर काम नहीं कर रहा है।जेस्ट मॉक कार्यान्वयन की आवश्यकता नहीं है ('')
यहाँ कोड
//Source implementation
var reference = require('./reference');
module.exports = {
getResult: function() {
return reference.result();
}
};
//Test code
jest.dontMock('./foo');
jest.dontMock('console');
describe('descirbe', function() {
var foo = require('./foo');
it('should ', function() {
var reference = require('./reference');
reference.result.mockImplementation(function (a, b, c) {
return '123'
});
console.log(foo.getResult()); // undefined
console.log(reference.result()); // 123
});
});