当我尝试在导入的函数上设置间谍时,我收到以下错误消息TypeError: Cannot read property '_isMockFunction' of undefined
我不明白这段代码有什么问题
导入的功能如下所示
export
function myFn(){
let htmlEl = document.querySelector('html');
let el = document.querySelector('.target-el');
if(el){
el.addEventListener('click', myInternalFn, false);
}
function myInternalFn () {
isUserLoggedIn((isIn) => {
let logoutClassName = 'el--logout';
if (isIn) {
el.classList.remove(logoutClassName);
return;
}
el.classList.add(logoutClassName);
});
}
function isUserLoggedIn (fn) {
return fn(localStorage.getItem('userLoggedIn') === 'true');
}
}
document.addEventListener('DOMContentLoaded', () => {
myFn();
});
TDD:
import { betSlip } from "../src/main/javascript/custom/betslip-dialog";
describe('Testing bet slip button (only on mobile)', function () {
let htmlEl;
let el;
beforeEach(() => {
document.body.innerHTML =
`
<html>
<div class="target-el"></div>
</html>
`;
myFn();
htmlEl = document.querySelector('html');
});
it('When el button has been clicked for the first time', done => {
jest.spyOn(myFn, 'myInternalFn');
myInternalFn.click();
expect(true).toBe(true);
done();
});
});