我正在构建一个Typescript单页面应用程序。其中一个端点返回已编译的Elm应用程序。
运行jest测试时,我收到以下错误:
yarn run v1.7.0
$ jest
PASS server/tests/experience/Albums.spec.ts
PASS server/tests/server.spec.ts
FAIL client/elm-stuff/packages/elm-lang/virtual-dom/2.0.4/tests/Native/TestHelpers.js
● Test suite failed to run
ReferenceError: Elm is not defined
> 1 | Elm.Native.TestHelpers = {};
| ^
2 | Elm.Native.TestHelpers.make = function(localRuntime)
3 | {
4 | localRuntime.Native = localRuntime.Native || {};
at Object.<anonymous> (client/elm-stuff/packages/elm-lang/virtual-dom/2.0.4/tests/Native/TestHelpers.js:1:28)
Test Suites: 1 failed, 2 passed, 3 total
Tests: 2 passed, 2 total
Snapshots: 1 passed, 1 total
Time: 0.669s, estimated 1s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
它在测试中看起来像Elm is not defined
。
但是,我确实在我的package.json依赖项中定义了Elm:
....
"dependencies": {
....
"elm": "0.18.0",
.....
},
...
我可以毫无问题地运行应用程序。
我在实际应用程序中对Elm的唯一引用是在我的HTML索引文件中。
<!DOCTYPE html>
<html>
<head>
<link rel='shortcut icon' type='image/x-icon' href='/favicon.ico' />
<link rel="stylesheet" href="/main.css">
<title>Print Albums</title>
</head>
<body>
<div id="elm-app"></div>
<script src="elm-compiled.js"></script>
<script>
const app = Elm.Main.embed(document.getElementById("elm-app"));
app.ports.grabToken.send(window.location.search);
</script>
</body>
</html>
你知道什么可能出错吗?由于某种原因看起来jest是在我的Elm依赖项中,而不仅仅是我的测试文件?
干杯
好吧,Stack Overflow再一次被证明是一只伟大的橡皮鸭。
发生了什么事:
解决方案是将client
添加到要被jest忽略的模式列表中。
testPathIgnorePatterns: [
"/node_modules/", "/client/"
],