我在下面的测试用例中需要一些帮助:appenChild 在 Jest 中失败
updatePopupContent(data) {
const sectionFragment = new DocumentFragment();
//create section return HTML element as per data passed
data.costSection && sectionFragment.appendChild(this.createSection(data.costSection));// test fails here
this.dom.content.appendChild(sectionFragment);
}
describe('test functionality', () => {
const data = {
costSection: {
price: "10 USD"
}
}
it("should create subsections ", () => {
context.createSection = jest.fn().mockImplementation(() => {
const section = document.createElement("div");
section.innerHTML = "Test Section";
return section;
})
context.updatePopupContent(data); // throwing error : TypeError: Cannot read property 'adoptNode' of undefined
expect(context.createSection).toHaveBeenCalledTimes(1);
})
实际上这是 JSDOM 的一个问题:https ://github.com/jsdom/jsdom/issues/2274 我需要在测试中进行哪些更改才能解决错误。
谢谢