Answer the question
In order to leave comments, you need to log in
How do mock functions work in JEST?
Testing the getlang
function . Inside it, get_language is used , so I write a mock function for it.
At the output I get *ReferenceError: get_language is not defined*
const getlang = require('./../j/lang');
const get_language = jest
.fn()
.mockReturnValue('ru');
console.log(get_language());
test('getlang return ERROR', () => {
expect(getlang()).toBe('lang error');
});
Answer the question
In order to leave comments, you need to log in
The problem was solved by writing the mock function to the global scope of the node
beforeAll(() => {
global.get_language =jest
.fn()
.mockReturnValue('ru');
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question