我正在构建一个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依赖中,而不仅仅是我的测试文件?
干杯
发布于 2018-09-11 17:29:40
好了,Stack Overflow再一次被证明是一个很好的橡皮鸭。
事情是这样的:
解决方案是将client添加到jest要忽略的模式列表中。
testPathIgnorePatterns: [
"/node_modules/", "/client/"
],https://stackoverflow.com/questions/52272781
复制相似问题