【发布时间】:2019-09-23 21:17:47
【问题描述】:
图书馆
- 开玩笑
- React 测试库
说明 当我对本身使用 smooth-dnd 的组件运行测试时。它工作正常。但是,当我运行所有测试时,我得到了这个非法调用错误。
来自 jsdom 库的 Node.js
Object.defineProperty(Node.prototype, "childNodes", {
get() {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation"); // Error here
}
return utils.getSameObject(this, "childNodes", () => {
return utils.tryWrapperForImpl(this[impl]["childNodes"]);
});
},
enumerable: true,
configurable: true
});
这是错误。
Test suite failed to run
TypeError: Illegal invocation
at Node.get [as childNodes] (node_modules/jsdom/lib/jsdom/living/generated/Node.js:423:13)
at Node.get (node_modules/smooth-dnd/dist/index.js:1:11462)
at node_modules/smooth-dnd/dist/index.js:1:11356
at node_modules/smooth-dnd/dist/index.js:1:96
at Object.<anonymous> (node_modules/smooth-dnd/dist/index.js:1:195)
at node_modules/react-smooth-dnd/dist/index.js:1:145`
似乎smooth-dnd调用了jsdom,而jsdom抛出了异常。但它只发生在我运行所有测试时。当我单独运行它们时,它们运行良好。
jsdom 中的节点是干什么用的?
根据代码,这一行正在捕获错误(!this || !module.exports.is(this)
为什么 Node 在我运行所有测试时未定义,但在我单独运行测试时定义?
是否有可能的解决方案,或者我应该尝试不同的拖放库。 任何帮助将不胜感激。
【问题讨论】:
-
请提供您用于测试的代码,以及有效的测试代码。