-1
rated 0 times
[
5]
[
6]
/ answers: 1 / hits: 35865
/ 11 Years ago, wed, november 27, 2013, 12:00:00
I've got the following service:
angular.module(services)
.factory(whatever, function($window) {
return {
redirect: function() {
$window.location.replace(http://www.whatever.com);
}
};
});
How to mock $window
object in unit test to prevent reloading the page when running tests?
I tried using
spyOn($window.location, 'replace').andReturn(true);
, but it didn't work (still got Some of your tests did a full page reload!
error) and
$provide.value('$window', {location: {replace: jasmine.createSpy()}})
, but I was getting an error (Error: [ng:areq] Argument 'fn' is not a function, got Object
) with stack trace pointing only to angular own source, so it wasn't very helpful...
More From » unit-testing