vendredi 4 septembre 2015

Expected spy go to have been called with [ 'stateName' ] but it was never called?

describe('Home Controller Test Suite', function() {

var HomeCtrl,$rootScope, $controller, $scope, $http, $state,factory;
var baseURL = "http://localhost:8000/";
beforeEach(module("ui.router"));
beforeEach(module("rbControllers"));

beforeEach(module("ui.bootstrap"));

beforeEach(module("toggle-switch"));
beforeEach(module("ngDraggable"));
beforeEach(module("angular-loading-bar"));
beforeEach(module("ngAnimate"));
beforeEach(module("kendo.directives"));

beforeEach(module("rbApp"));



beforeEach(inject(function(_$rootScope_ ,_$controller_,_$httpBackend_, _$state_){
    $rootScope = _$rootScope_;
    $scope = $rootScope.$new();
    $controller = _$controller_;
    httpBackend = _$httpBackend_;
    $state = _$state_;
    HomeCtrl = $controller('HomeCtrl', {'$scope': $scope, '$state': $state, 'baseURL' : baseURL, 'roobrickUiService': factory});
}));


it("Test: HomeCtrl exists or not", function() {
    expect(HomeCtrl).toBeDefined();

});


 it("Test:xxx run", function() {
    spyOn($state, 'go');
    expect($state.go).toHaveBeenCalledWith('stateName');

 });

});

spyOn($state, 'go');

This is working fine

expect($state.go).toHaveBeenCalledWith('stateName');

But when i execute above line its not working and giving 'Expected spy go to have been called with [ 'stateName' ] but it was never called' this error please help me in this

Aucun commentaire:

Enregistrer un commentaire