安装Jasmine失败

时间:2015-01-23 13:12:33

标签: html jasmine

我正在尝试让Jasmine在我的网站上工作。这是我的HTML:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Jasmine Spec Runner v2.1.3</title>
<link rel="stylesheet" type="text/css" href="/Content/css/jasmine.css" />
<script src="/Scripts/UnitTesting/boot.js"></script>
<script src="/Scripts/UnitTesting/jasmine-html.js"></script>
<script src="/Scripts/UnitTesting/jasmine.js"></script>
<!-- include source files here... -->

<!-- include spec files here... -->
<script src="/Scripts/UnitTesting/HelloWorldSpec.js"></script>

</head>
<body>
</body>
</html>

HelloWorldSpec.js:

function helloWorld() {
    return "Hello world!";
}

describe("Hello world", function () {
    it("says hello", function () {
        expect(helloWorld()).toEqual("Hello world!");
    });
});

当我加载此页面时,我得到:

ReferenceError: jasmineRequire is not defined
ReferenceError: describe is not defined

我以为我错误地引用了JS文件。但是当我查看页面源代码并单击其中一个js链接时,例如“/Scripts/UnitTesting/boot.js”,我看到了源代码,因此看起来文件已成功加载。这里出了什么问题?

1 个答案:

答案 0 :(得分:2)

boot.js文件应该在jasmine.jsjasmine-html.js之后加载,否则它会启动什么?您应该包含文件的正确顺序是:

  1. jasmine.js
  2. jasmine-html.js
  3. boot.js
  4. http://jasmine.github.io/2.0/boot.html

      

    从版本2.0开始,此文件“启动”Jasmine,在执行加载的环境和所有项目规范之前执行所有必要的初始化。 此文件应在jasmine.js和jasmine_html.js之后加载,但在加载任何项目源文件或规范文件之前。因此,此文件也可用于为项目自定义Jasmine。