mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-18 15:50:22 +00:00
- Speed improvements (about 4x on flush phase) - Memory improvements (uses no function closures) - Break $eval into $apply, $dispatch, $flush - Introduced $watch and $observe Breaks angular.equals() use === instead of == Breaks angular.scope() does not take parent as first argument Breaks scope.$watch() takes scope as first argument Breaks scope.$set(), scope.$get are removed Breaks scope.$config is removed Breaks $route.onChange callback has not "this" bounded
78 lines
2 KiB
JavaScript
78 lines
2 KiB
JavaScript
'use strict';
|
|
|
|
describe('$defer', function() {
|
|
var scope, $browser, $defer, $exceptionHandler;
|
|
|
|
beforeEach(function(){
|
|
scope = angular.scope(angular.service,
|
|
{'$exceptionHandler': jasmine.createSpy('$exceptionHandler')});
|
|
$browser = scope.$service('$browser');
|
|
$defer = scope.$service('$defer');
|
|
$exceptionHandler = scope.$service('$exceptionHandler');
|
|
});
|
|
|
|
afterEach(function(){
|
|
dealoc(scope);
|
|
});
|
|
|
|
|
|
it('should delegate functions to $browser.defer', function() {
|
|
var counter = 0;
|
|
$defer(function() { counter++; });
|
|
|
|
expect(counter).toBe(0);
|
|
|
|
$browser.defer.flush();
|
|
expect(counter).toBe(1);
|
|
|
|
$browser.defer.flush(); //does nothing
|
|
expect(counter).toBe(1);
|
|
|
|
expect($exceptionHandler).not.toHaveBeenCalled();
|
|
});
|
|
|
|
|
|
it('should delegate exception to the $exceptionHandler service', function() {
|
|
$defer(function() {throw "Test Error";});
|
|
expect($exceptionHandler).not.toHaveBeenCalled();
|
|
|
|
$browser.defer.flush();
|
|
expect($exceptionHandler).toHaveBeenCalledWith("Test Error");
|
|
});
|
|
|
|
|
|
it('should call $apply after each callback is executed', function() {
|
|
var applySpy = this.spyOn(scope, '$apply').andCallThrough();
|
|
|
|
$defer(function() {});
|
|
expect(applySpy).not.toHaveBeenCalled();
|
|
|
|
$browser.defer.flush();
|
|
expect(applySpy).toHaveBeenCalled();
|
|
|
|
applySpy.reset(); //reset the spy;
|
|
|
|
$defer(function() {});
|
|
$defer(function() {});
|
|
$browser.defer.flush();
|
|
expect(applySpy.callCount).toBe(2);
|
|
});
|
|
|
|
|
|
it('should call $apply even if an exception is thrown in callback', function() {
|
|
var applySpy = this.spyOn(scope, '$apply').andCallThrough();
|
|
|
|
$defer(function() {throw "Test Error";});
|
|
expect(applySpy).not.toHaveBeenCalled();
|
|
|
|
$browser.defer.flush();
|
|
expect(applySpy).toHaveBeenCalled();
|
|
});
|
|
|
|
it('should allow you to specify the delay time', function(){
|
|
var defer = this.spyOn($browser, 'defer');
|
|
$defer(noop, 123);
|
|
expect(defer.callCount).toEqual(1);
|
|
expect(defer.mostRecentCall.args[1]).toEqual(123);
|
|
});
|
|
});
|