茉莉花测试不运行

时间:2015-04-14 15:25:50

标签: angularjs jasmine

我正在尝试在我的Angular应用程序上设置Jasmine测试来测试控制器。

控制器:

    var navigation = angular.module("navigation", []);

navigation.controller("NavigationController", ['$scope', function ($scope) {
    $scope.myObject = [];
    $scope.tabs = [
        { title: "Surcharge Index", content: "SurchargeIndex" },
        { title: "Scheduling and Adjustments", content: "Scheduling" },
        { title: "Auto Update Settings", content: "Automation" },
        { title: "Processing Rules", content: "FuelProcessing" },
        { title: "Data Update ", content: "DataUpdate" },

    ];
}]);

测试:

    describe("NavigationController", function () {
    var scope;
    var controller;

    //beforeEach(module('app'));

    beforeEach(inject(function ($controller, $rootScope) {
        scope = $rootScope.$new();
        controller = $controller('NavigationController', { '$scope': scope });
        }));

    it("scope is defined", function () {
        expect(scope).toBeDefined();
        //expect(scope.tags[0].title).toBe('Doe Index');
    });

    it("should contain a list of tabs", function () {
        //expect(scope).toBeDefined();
        expect(scope.tags).toContain({ title: 'Doe Index' });
    });

});

Jasmine测试都没有运行过。

测试页面:

Jasmine2.0.0finished in 0.001s
raise exceptions
Ran 0 of 2 specs - run all
0 specs, 0 failures
NavigationController
scope is defined
should contain a list of tabs

这就是Jasmine的回归。由于某种原因,没有一项测试正在进行。

有什么建议吗?

2 个答案:

答案 0 :(得分:1)

您必须加载正在测试的模块:

beforeEach(module('navigation'));

添加你所拥有的地方:

//beforeEach(module('app'));

但没有注释。

答案 1 :(得分:0)

一旦我意识到我需要加载模块,我就用这个OdeToCode帖子作为样本。我的测试用例现在看起来像这样。

describe("myApp", function () {
    beforeEach(module('navigation'));

    describe("NavigationController", function() {
        var scope;
        var controller;

        beforeEach(inject(function($controller, $rootScope) {
            jasmine.addMatchers(customMatcher);
            scope = $rootScope.$new();
            controller = $controller('NavigationController', { '$scope': scope });
        }));

        it("scope is defined", function() {
            expect(scope).toBeDefined();
        });

        it("should contain a list of tabs", function() {
            expect(scope.tabs.length).toBe(5);
        });
    });
)};