javascript - Q-Unit 全局故障
问题描述
我刚刚尝试为我的 javascript 函数设置 Q-Unit 测试。但是,我似乎收到了Global Failure的错误
在我的 JS 文件 :script.js
中,我必须在所有 JS 代码之上都有测试代码,否则单元测试不会运行,我只会收到全局失败消息。但是,如果我将单元测试粘贴到所有 JS 函数之上,测试就会运行,但我仍然会收到全局失败错误。
有人可以指导正确的方向。
测试脚本.html:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Q-Unit Tests</title>
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.10.0.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="https://code.jquery.com/qunit/qunit-2.10.0.js" integrity="sha256-X1fQXHSYGxa4V2bqkEAQW0DQGSxJrKveasahr959o28=" crossorigin="anonymous"></script>
<script src="script.js"></script>
</body>
</html>
脚本.js:
function square(x) {
return x * x;
}
QUnit.test( "square", function( assert ) {
var result = square(2);
assert.equal( result, "4", "square(2) should be 4." );
});
//Normal JS functions are below here
解决方案
正如我认为的那样,我通过包含已解决全局故障错误的 jQuery 的 CDN 链接来发布此问题的答案,因为它不再出现。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
推荐阅读
- asp.net-mvc - Azure Application Insights - AI(内部):24 条消息:“缺少必填字段规范
- excel - 自动扩展包含前面单元格中的中间公式的公式
- php - “无”与负前瞻
- css - css 过渡 - 悬停在元素上时的问题
- java - 迭代时将项目添加到列表中的特定索引中
- jquery - 单击按钮时增加和减少图像宽度
- php - Angular 应用程序中的 CORS 问题
- ssl-certificate - 如何从 gcloud 设置 SSL 证书?
- python-3.x - 无法在 Pycharm 中访问 Python 中的环境变量
- json - 如何在 servlet 中读取 json 值?