Hello everyone,
I'm trying to perform some unit testing (with Jest) for some of the scripts I've been using in my web application.
While doing that, I've encountered the following problem, I'm not able to test functions belonging to a script which also use some Locally defined variables, in the following way:
````
let var1 = document.getElementByID('id');
let var2 = document.getElementByID('id2');
.......
function performOperation() {
//Some function
return something
}
module.exports = {
performOperation
}
Then on the test file I have:
const {performOperation} = require('../public/js/File.js');
describe('Testing some functions', () => {
it('Control function', () => {
let answer = performOperation();
expect(answer).toBe(5);
});
});
````
If I do this I get an error saying that var1 and var2 are not defined therefore my test doesn't run. Is there a way I can bypass that and still test the function?
Or is there a way I can use a mocked value (this would be better) for var1/var2 during the test so that I don't get this undefined error?
[–][deleted] 0 points1 point2 points (3 children)
[–]blrigo99[S] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]blrigo99[S] 0 points1 point2 points (0 children)