gpt4 book ai didi

javascript - 引用错误: mock is not defined Javascript

转载 作者:行者123 更新时间:2023-12-03 06:33:02 43 4
gpt4 key购买 nike

启动一切的主js文件:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>InterfaceTest</title>
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.0.0.css">
<script type="text/javascript" src="https://rawgit.com/angular/bower-angular-mocks/master/angular-mocks.js"></script>

<script src="https://code.jquery.com/qunit/qunit-2.0.0.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.2.4.min.js"></script>
<script type="text/javascript" src="https://rawgit.com/danielfm/jshamcrest/master/src/jshamcrest.js"></script>
<script type="text/javascript" src="https://rawgit.com/cleishm/jsmockito/master/src/jsmockito.js"></script>

<script src="Interface.js" ></script>
<script src="InterfaceTest.js" ></script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
</body>
</html>

接口(interface)测试:

QUnit.test("mockitoTest", function(assert) {
var mockedObject = mock(Array);
when(mockedObject).get(1).thenReturn("hello world");
alert(mockedObject.get(1));
});

我需要使用 Jquery、Hamcrest 和 JsMockito 为 Interface 进行一系列单元测试(不管里面有什么)。

我得到的错误:

Died on test #1     at file:///C:/Internship/JavaScript/Qunit/InterfaceTest.js:1:7: mock is not defined@ 
Source:
ReferenceError: mock is not defined
at Object.<anonymous> (file:///C:/Internship/JavaScript/Qunit/InterfaceTest.js:2:21)

我确信这是显而易见的,但我已将 Mockito 作为依赖项包含在内,所以我不知道为什么它说“mock 未定义”。我的假设是

 <script `type="text/javascript" src="https://rawgit.com/cleishm/jsmockito/master/src/jsmockito.js"></script>

肯定是错的。

(我在另一篇 stackoverflow 帖子中看到,如果您在 https://rawgit.com/ 上发布 github 链接,那么您可以将其包含为 src,因此这些链接就是来自于此)

最佳答案

当我运行你的代码时,我看到错误无法设置未定义的模拟并指向angular-mocks.js文件。

文件 angular-mocks.js 需要 Angular,但您不加载 Angular。

关于javascript - 引用错误: mock is not defined Javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38360495/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com