Jestjs 在jest测试中使用JSDOM
我想在我的jest测试套装中使用JSDOM。然而,虽然JSDOM standalone工作得很完美,但当我在jest测试中运行它时,它会抛出关于编码的奇怪错误。 看那个片段Jestjs 在jest测试中使用JSDOM,jestjs,jsdom,Jestjs,Jsdom,我想在我的jest测试套装中使用JSDOM。然而,虽然JSDOM standalone工作得很完美,但当我在jest测试中运行它时,它会抛出关于编码的奇怪错误。 看那个片段 const { JSDOM } = require("jsdom"); describe("suit", () => { test("test", () => { JSDOM.fromURL("your_url", {}).then(dom => { expect(1).toBe(
const { JSDOM } = require("jsdom");
describe("suit", () => {
test("test", () => {
JSDOM.fromURL("your_url", {}).then(dom => {
expect(1).toBe(1);
});
});
});
上面的代码段根据您的url抛出错误:编码未识别:'ISO-8859-2'(搜索为:'iso88592')
(例如)或错误:编码未识别:'UTF-8'(搜索为:'utf8')
(例如)。没有url我可以让它工作,总是上面描述的两个错误中的一个。但是,当您运行时:
const { JSDOM } = require("jsdom");
JSDOM.fromURL("https://example.com/", {}).then(dom => {
console.log(dom.serialize());
});
这是它应该做的。复制回购:
环境信息:
System:
OS: macOS Mojave 10.14.3
CPU: (4) x64 Intel(R) Core(TM) i7-4578U CPU @ 3.00GHz
Binaries:
Node: 12.14.0 - ~/.nvm/versions/node/v12.14.0/bin/node
Yarn: 1.21.1 - /usr/local/bin/yarn
npm: 6.13.4 - ~/.nvm/versions/node/v12.14.0/bin/npm
npmPackages:
jest: ^24.9.0 => 24.9.0
完整错误列表:
npm test
> test_jsdom@1.0.0 test /Users/grzegorz/Projects/Meteor/playground/test_jsdom
> jest
PASS __tests__/test.js
suit
✓ test (35ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 1.93s
Ran all test suites.
(node:13599) UnhandledPromiseRejectionWarning: Error: Encoding not recognized: 'ISO-8859-2' (searched as: 'iso88592')
(node:13599) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:13599) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated.
这回答了你的问题吗?这回答了你的问题吗?