簡體   English   中英

使用Jasmine測試AngularJS控制器

[英]Testing AngularJS controller with Jasmine

我有以下NewPageCtrl.js

angular.module('NewPageCtrl', []).controller('NewPageController', function($scope, $document) {

    $scope.showMe = false;

});

和下面的test.js

describe('NewPageCtrl', function() {
var scope, $document, createController;

beforeEach(inject(function ($rootScope, $controller _$document_) {
    $document = _$document_;
    scope = $rootScope.$new();

    createController = function() {
        return $controller('NewPageCtrl', {
            '$scope': scope
        });
    };
}));

it('should check showMe', function() {

});
});

稍后我將編寫測試用例,但是現在Jasmine給了我錯誤:

 Chrome 48.0.2564 (Mac OS X 10.10.5) ERROR
 Uncaught SyntaxError: Unexpected identifier
 at /Users/me/myProject/test/test.js:23

第23行是beforeEach(...

我從http://nathanleclaire.com/blog/2013/12/13/how-to-unit-test-controllers-in-angularjs-without-setting-your-hair-on-fire/獲得了示例

您錯過了一個逗號。

更改

$rootScope, $controller _$document_

$rootScope, $controller, _$document_

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM