Skip to content

Instantly share code, notes, and snippets.

@diegodelfin7
Forked from jakebern/controller.js
Created January 3, 2018 19:33
Show Gist options
  • Save diegodelfin7/37cb50f60147a7219be86ea1f7a66ee3 to your computer and use it in GitHub Desktop.
Save diegodelfin7/37cb50f60147a7219be86ea1f7a66ee3 to your computer and use it in GitHub Desktop.
Jasmine Testing - Injecting and testing for state change
.controller('A', function($scope, $state){
$scope.functionA = function(ID){
$state.go('next-state', {number: ID});
};
})
describe('Controller: A', function () {
var scope;
var A;
beforeEach(function () {
module('sample');
module('ui.router');
inject(function ($rootScope, $controller,$httpBackend, $state) {
scope = $rootScope.$new();
FindDetailCtrl = $controller('A', {
$scope: scope,
});
$state={
go: function(state, args){}
}
});
});
it('should change state and include paramter', inject(function($controller, $rootScope, environment, $httpBackend) {
spyOn($state, 'go')
scope.functionA(25);
expect($state.go).toHaveBeenCalledWith('next-state', { number: 25 });
}));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment