单元测试茉莉花

时间:2016-04-21 10:48:31

标签: jasmine

我试图编写如下规范,但无法运行它,下面是我使用的示例文件 的 Sample.js

(function (app) {

    var SimpleController = function ($scope) {

        $scope.x = 3;
        $scope.y = 4;
        $scope.doubleIt = function () {
            $scope.x *= 2;
            $scope.y *= 2;
        };
    };

    app.controller("SimpleController", 
             ["$scope", SimpleController]);

}(angular.module("myApp")));

Spec.js

describe("myApp", function() {

    beforeEach(module('myApp'));

    describe("SimpleController", function() {

        var scope;
        beforeEach(inject(function($rootScope, $controller) {
            scope = $rootScope.$new();
            $controller("SimpleController", {
                $scope: scope
            });
        }));

        it("should double the numbers", function() {
            scope.doubleIt();
            expect(scope.x).toBe(6);
        });
    });
});

我有js文件 - jasmine.js

  • 茉莉html.js
  • angular.js
  • 角mocks.js
  • sample.js

运行规范时会显示 错误:没有模块:myApp
TypeError:无法获取属性'doubleIt'的值:object为null或undefined

请帮我解决这个问题

0 个答案:

没有答案