提问人:chilly_maximus 提问时间:1/8/2020 最后编辑:skyboyerchilly_maximus 更新时间:1/8/2020 访问量:752
在 jest 测试中使用 JSDOM
Using JSDOM in jest tests
问:
我想在我的玩笑测试套装中使用 JSDOM。然而,虽然 JSDOM 独立运行完美,但当我在 jest test 中运行它时,它会抛出关于编码的奇怪错误。 看看那个片段
const { JSDOM } = require("jsdom");
describe("suit", () => {
test("test", () => {
JSDOM.fromURL("your_url", {}).then(dom => {
expect(1).toBe(1);
});
});
});
上面的片段取决于your_url抛出(例如 https://gazeta.pl)或(例如 https://github.com)。没有 url 我能够使它工作,总是上面描述的两个错误中的一个。但是,当您运行:Error: Encoding not recognized: 'ISO-8859-2' (searched as: 'iso88592')
Error: Encoding not recognized: 'UTF-8' (searched as: 'utf8')
const { JSDOM } = require("jsdom");
JSDOM.fromURL("https://example.com/", {}).then(dom => {
console.log(dom.serialize());
});
它按应有的方式工作。复制回购:https://github.com/pociej/jsdom_problem_reproduction。
环境信息:
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
> [email protected] 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.
答: 暂无答案
评论