I have a function in my Angular controller that looks like this:
$scope.myFunction = function(){ $scope.myVariable = "something"; $scope.myOtherVariable = "something else"; window.location.href = "/path/to/page"; }
A simple Jasmine test covers the above function and is as follows:
describe('my test', function(){ it('should pass', function(){ scope.myFunction(); expect(scope.myVariable).toBe('something'); expect(scope.myOtherVariable).toBe('something else'); }); });
The above test passes, but then Karma gives the following error in the console:
Some of your tests completely reloaded the page!
Redirecting a page causes Karma to raise this warning. What is the best way to get around this?
I thought about providing anonymous functions in the Jasmine test and Angular names, and then using arguements.callee.caller.name inside the original function to determine if the function is being called on its own or Jasmine. Unfortunately, arguments.callee.caller.name always returns undefined, which I suspect is caused by how Angular and Jasmine are related to each other.
angularjs karma-runner jasmine karma-jasmine
Lloyd banks
source share