forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocumentSpec.js
55 lines (41 loc) · 1.6 KB
/
documentSpec.js
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
'use strict';
describe('$document', function() {
it('should inject $document', inject(function($document) {
expect($document).toEqual(jqLite(window.document));
}));
it('should be able to mock $document object', function() {
module({$document: {}});
inject(function($httpBackend, $http) {
$httpBackend.expectGET('/dummy').respond('dummy');
$http.get('/dummy');
$httpBackend.flush();
});
});
it('should be able to mock $document array', function() {
module({$document: [{}]});
inject(function($httpBackend, $http) {
$httpBackend.expectGET('/dummy').respond('dummy');
$http.get('/dummy');
$httpBackend.flush();
});
});
});
describe('$$isDocumentHidden', function() {
it('should listen on the visibilitychange event', function() {
var doc;
var spy = spyOn(window.document, 'addEventListener').and.callThrough();
inject(function($$isDocumentHidden, $document) {
expect(spy.calls.mostRecent().args[0]).toBe('visibilitychange');
expect(spy.calls.mostRecent().args[1]).toEqual(jasmine.any(Function));
expect($$isDocumentHidden()).toBeFalsy(); // undefined in browsers that don't support visibility
});
});
it('should remove the listener when the $rootScope is destroyed', function() {
var spy = spyOn(window.document, 'removeEventListener').and.callThrough();
inject(function($$isDocumentHidden, $rootScope) {
$rootScope.$destroy();
expect(spy.calls.mostRecent().args[0]).toBe('visibilitychange');
expect(spy.calls.mostRecent().args[1]).toEqual(jasmine.any(Function));
});
});
});