我正在使用 mocha
进行单元测试,并尝试在单元测试中使用 jsdom
进行 html
元素。
我下载了 jsdom.zip
并导入了测试库,但遇到了这个错误:
jsdom/living/attributes.js:114 for (const name of Object.getOwnPropertyNames(prototype)) { ^^ SyntaxError: Unexpected identifier
我尝试在 Google 上查找此错误消息的原因,但遗憾的是我无法找到答案。
最佳答案
最新的 JSDOM 不适用于旧版本的 Node(语法错误可能是 ES6 const
)。作为readme说:
Note that as of our 4.0.0 release, jsdom no longer works with Node.js™, and instead requires io.js. You are still welcome to install a release in the 3.x series if you use Node.js™.
尝试升级到latest Node或下载版本 3.x(另外,NPM 可能比下载 ZIP 文件更容易:)
关于javascript - attribute.js 中的 JSDOM 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30983600/