In one of my controllers, I have the following code snippet:
$scope.foo = function(){
return RolesService.remove({
data: role
})
.then(function (v) {
if (!(v && v.cdtError)) {
$window.location.reload();
}
});
}
I have injected $window
into the controller.
Within my unit test, I tried to create a stub for window.location.reload
using the following code:
let $window = {location: {reload: sinon.spy()}};
module(function ($provide) {
$provide.value('$window', $window);
$window.onbeforeunload = sinon.spy();
});
However, the stub doesn't seem to be effective as I continue to encounter this error message:
Some of your tests did a full page reload!
How can I properly stub window.location.reload
to prevent this from happening?
I have looked at some discussions on the Karma Github issue tracker regarding this problem, but I haven't found a satisfactory solution yet.