From 62761428eff3a53e69367449eb81869e59e75e39 Mon Sep 17 00:00:00 2001 From: Matias Niemelä Date: Mon, 24 Feb 2014 19:21:20 -0500 Subject: chore(core): create a wrapper to manage async callbacks --- test/ng/asyncCallbackSpec.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test/ng/asyncCallbackSpec.js (limited to 'test/ng/asyncCallbackSpec.js') diff --git a/test/ng/asyncCallbackSpec.js b/test/ng/asyncCallbackSpec.js new file mode 100644 index 00000000..f9bbe781 --- /dev/null +++ b/test/ng/asyncCallbackSpec.js @@ -0,0 +1,33 @@ +'use strict'; +describe('$$asyncCallback', function() { + it('should perform a callback asynchronously', inject(function($$asyncCallback) { + var message = 'hello there '; + $$asyncCallback(function() { + message += 'Angular'; + }); + + expect(message).toBe('hello there '); + $$asyncCallback.flush(); + expect(message).toBe('hello there Angular'); + })); + + describe('mocks', function() { + it('should queue up all async callbacks', inject(function($$asyncCallback) { + var callback = jasmine.createSpy('callback'); + $$asyncCallback(callback); + $$asyncCallback(callback); + $$asyncCallback(callback); + expect(callback.callCount).toBe(0); + + $$asyncCallback.flush(); + expect(callback.callCount).toBe(3); + + $$asyncCallback(callback); + $$asyncCallback(callback); + expect(callback.callCount).toBe(3); + + $$asyncCallback.flush(); + expect(callback.callCount).toBe(5); + })); + }); +}); -- cgit v1.2.3