javascript - 尝试运行 QUnit 测试但找不到明确定义的函数
问题描述
我已经在我正在运行的测试中调整了这个例子
https://embed.plnkr.co/plunk/OJpuhX
在测试中,导入功能失败,但我找到了解决方法。
这是该示例中的代码块:
索引.html
<!DOCTYPE html>
<html>
<head>
<link data-require="qunit@*" data-semver="1.17.1" rel="stylesheet"
href="http://code.jquery.com/qunit/qunit-1.17.1.css" />
<script data-require="qunit@*" data-semver="1.17.1" src="http://code.jquery.com/qunit/qunit-1.17.1.js"></script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script>
<script src="hello.js"></script>
<script src="hello.test.js"></script>
</body>
</html>
添加.js
export class showAlert {
static msg() {
alert('Hello World!');
// retmsg = 'Hello World!'
// return retmsg;
}
}
你好.test.js
import ('hello.ts');
QUnit.test("hello test", function (assert) {
assert.ok(hello.hello() === 'Hello World!', 'Passed!');
});
hello.ts(以前的 hello.js),如果它是 ts 由于 IMPORT 不能在模块之外工作,我无法导入
var hello: any;
import { showAlert as _alert } from './add';
hello = function hello() {
alert('MakeTest: ' + _alert);
return 'Hello World!';
};
alert('Hello var: ' + hello);
我经常得到的错误是:
PS C:\Users\pborregg\repos\wwwroot\acquisition-global-components\src> npm test
> acquisition-aem-global-components@1.0.0 test C:\Users\pborregg\repos\wwwroot\acquisition-global-components\src
> karma start
START:
19 05 2021 13:31:35.547:WARN [filelist]: Pattern "C:/Users/pborregg/repos/wwwroot/acquisition-global-components/src/hello.js" does not match any file.
19 05 2021 13:31:35.600:INFO [karma-server]: Karma v6.3.2 server started at http://localhost:9876/
19 05 2021 13:31:35.643:INFO [launcher]: Launching browsers Chrome with concurrency unlimited
19 05 2021 13:31:35.704:INFO [launcher]: Starting browser Chrome
19 05 2021 13:31:40.045:INFO [Chrome 90.0.4430.212 (Windows 10)]: Connected on socket lmNGV4w5POgtxbWPAAAB with id 46008113
× hello test
Finished in 0.018 secs / 0.003 secs @ 13:31:40 GMT-0700 (Pacific Daylight Time)
SUMMARY:
√ 0 tests completed
× 1 test failed
FAILED TESTS:
× hello test
Chrome 90.0.4430.212 (Windows 10)
Died on test #1 at hello.test.js:12:7: hello is not defined
ReferenceError: hello is not defined
at Object.<anonymous> (hello.test.js:13:15)
at runTest (C:/Users/pborregg/node_modules/qunit/qunit/qunit.js:2251:37)
at Test.run (C:/Users/pborregg/node_modules/qunit/qunit/qunit.js:2239:9)
at C:/Users/pborregg/node_modules/qunit/qunit/qunit.js:2461:16
at processTaskQueue (C:/Users/pborregg/node_modules/qunit/qunit/qunit.js:1849:33)
at C:/Users/pborregg/node_modules/qunit/qunit/qunit.js:1853:13
npm ERR! Test failed. See above for more details.
笔记:
要自己尝试一下,请将所有内容放在同一个文件夹中。
感谢您的帮助。
解决方案
推荐阅读
- android-studio - 我们可以在环境变量中添加两个 PATH 吗?
- batch-file - 注销用户的批处理文件不起作用
- c++ - 指针声明中的星号是运算符吗?
- go - Go 无法接收以太网帧
- c# - 在 DlibDotNet 中提取检测到的人脸
- powershell - Copy-Item 按字符串递归
- c# - 如何使用带有 WHERE 子句的 T-SQL 将我计算机中目录路径中的图像插入 SQL Server 二进制列
- go - goroutine中的Websockets:错误之前的消息未读取完成
- swift - 如何从 ARAnchor 到达 2D 坐标系?
- javascript - 如何将 IEnumerable 转换为 javascript 数组