2016-06-07 19 views
3

我試圖使用createSpy()設置模擬單元測試與茉莉花。我在收到如何使用createSpy創建模擬對象()

TypeError: undefined is not a function (evaluating jasmine.createSpy().andCallFake(function(msg) { return [] })) (line 13).

CODE:

$scope.workInit = function() { 
    $scope.work_loading = true; 
    $scope.public_work_loading = true; 

    var projects = SomeService.getGroups(); 
    var publicProjects = SomeService.getPublicGroupings('G'); 
    … 
    ... 
    } 

TEST:

this.SomeService = { 
    getGroups: jasmine.createSpy().andCallFake(function(msg) { return [] }), 
    getPublicGroupings: jasmine.createSpy().andCallFake(function(msg) { return [] }), 
} 

    it('should expect work_loading and public_loading to be false', function() { 
    this.scope.workInit(); 
    expect($scope.work_loading).toEqual(false); 
    expect($scope.public_work_loading).toEqual(false); 
    }); 
+1

'this.scope.workInit();'或'** this.scope.workgInit();'** ? –

+0

其this.scope.workInit();對不起,這是一個錯字。我會更新,謝謝 – Jason

回答

0

您已經設置了模擬單元測試用例的方法是正確的,同樣的作品我在this fiddle

檢查中,你已經包括了這部分代碼範圍:

this.SomeService = { 
    getGroups: jasmine.createSpy().andCallFake(function(msg) { return [] }), 
    getPublicGroupings: jasmine.createSpy().andCallFake(function(msg) { return [] }),