fix($$rAF): always fallback to a $timeout incase native rAF isn't supported

Closes #6654
This commit is contained in:
Matias Niemelä
2014-03-14 12:01:45 -04:00
parent a41a2a1d2c
commit ee8e4a946e
2 changed files with 48 additions and 8 deletions

View File

@@ -31,6 +31,38 @@ describe('$$rAF', function() {
expect(present).toBe(true);
}));
describe('$timeout fallback', function() {
it("it should use a $timeout incase native rAF isn't suppored", function() {
var timeoutSpy = jasmine.createSpy('callback');
//we need to create our own injector to work around the ngMock overrides
var injector = createInjector(['ng', function($provide) {
$provide.value('$timeout', timeoutSpy);
$provide.decorator('$window', function($delegate) {
$delegate.requestAnimationFrame = false;
$delegate.webkitRequestAnimationFrame = false;
$delegate.mozRequestAnimationFrame = false;
return $delegate;
});
}]);
var $$rAF = injector.get('$$rAF');
expect($$rAF.supported).toBe(false);
var message;
$$rAF(function() {
message = 'on';
});
expect(message).toBeUndefined();
expect(timeoutSpy).toHaveBeenCalled();
timeoutSpy.mostRecentCall.args[0]();
expect(message).toBe('on');
});
});
describe('mocks', function() {
it('should throw an error if no frames are present', inject(function($$rAF) {
if($$rAF.supported) {