简体   繁体   English

单元测试中的Javascript参考错误

[英]Javascript Reference Error in Unit Test

I am writing unit tests for my angularjs solution using jasmine and chutzpah and I keep getting a ReferenceError saying the it cant find a variable module... 我正在使用茉莉花和chutzpah为我的angularjs解决方案编写单元测试,并且不断收到ReferenceError说它找不到可变模块...

this are the error messages I keep getting: 这是我不断收到的错误消息:

Test Name: appControllersTest encountered a declaration exception Test FullName: ..\\scripts_references.js::appcontrollerstest::encountered a declaration exception Test Source: ..\\scripts_references.js : line 0 Test Outcome: Failed Test Duration: 0:00:00.001 Result Message: ReferenceError: Can't find variable: module in file:../scripts/unittest/controllerstest.js:20 测试名称:appControllersTest遇到声明异常测试全名:.. \\ scripts_references.js :: appcontrollerstest ::遇到声明异常测试源:.. \\ scripts_references.js:第0行测试结果:测试失败持续时间:0:00:00.001结果消息:ReferenceError:找不到变量:文件:../ scripts / unittest / controllerstest.js:20中的模块

Test Name: appControllersTest encountered a declaration exception Test FullName: ..\\scripts\\unittest\\controllerstest.js::appcontrollerstest::encountered a declaration exception Test Source: ..\\scripts\\unittest\\controllerstest.js : line 16 Test Outcome: Failed Test Duration: 0:00:00.001 Result Message: ReferenceError: Can't find variable: module in file:../scripts/unittest/controllerstest.js:20 测试名称:appControllersTest遇到声明异常测试全名:.. \\ scripts \\ unittest \\ controllerstest.js :: appcontrollerstest ::遇到声明异常测试源:.. \\ scripts \\ unittest \\ controllerstest.js:第16行测试结果:失败测试持续时间:0:00:00.001结果消息:ReferenceError:找不到变量:文件中的模块:../ scripts / unittest / controllerstest.js:20

this is my unit test: 这是我的单元测试:

/// <reference path="../_references.js" />
/// <reference path="../AngularJSApp/controllers.js" />

describe("appControllersTest", function () {
    var $scope;

    beforeEach(module("appMain"));

    describe("RRCtrl", function () {

        beforeEach(inject(function ($controller) {
            $scope = {};
            $controller("RRCtrl", { $scope: $scope });
        }));

        it("JavaTestTest", function ($controller) {
            expect(scope.$root.title).toBe("");
        });
    });
});

Has anyone encountered this kind of error and how do you fix it? 有没有人遇到过这种错误,您该如何解决?

Figured out what was wrong. 找出问题所在。 Some of the references where declared in the wrong order in _reference.js. 某些引用在_reference.js中以错误的顺序声明。 After changing it manually it worked. 手动更改后,它可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM