aboutsummaryrefslogtreecommitdiffstats
path: root/test/ng/asyncCallbackSpec.js
blob: f9bbe781206214cb3832251e43c95fa2c6fa473d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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);
    }));
  });
});