forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathngEventDirsSpec.js
102 lines (76 loc) · 3.07 KB
/
ngEventDirsSpec.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
'use strict';
describe('event directives', function() {
var element;
afterEach(function() {
dealoc(element);
});
describe('ngSubmit', function() {
it('should get called on form submit', inject(function($rootScope, $compile) {
element = $compile('<form action="" ng-submit="submitted = true">' +
'<input type="submit"/>' +
'</form>')($rootScope);
$rootScope.$digest();
expect($rootScope.submitted).not.toBeDefined();
browserTrigger(element.children()[0]);
expect($rootScope.submitted).toEqual(true);
}));
it('should expose event on form submit', inject(function($rootScope, $compile) {
$rootScope.formSubmission = function(e) {
if (e) {
$rootScope.formSubmitted = 'foo';
}
};
element = $compile('<form action="" ng-submit="formSubmission($event)">' +
'<input type="submit"/>' +
'</form>')($rootScope);
$rootScope.$digest();
expect($rootScope.formSubmitted).not.toBeDefined();
browserTrigger(element.children()[0]);
expect($rootScope.formSubmitted).toEqual('foo');
}));
});
describe('focus', function() {
it('should call the listener asynchronously during $apply',
inject(function($rootScope, $compile) {
element = $compile('<input type="text" ng-focus="focus()">')($rootScope);
$rootScope.focus = jasmine.createSpy('focus');
$rootScope.$apply(function() {
element.triggerHandler('focus');
expect($rootScope.focus).not.toHaveBeenCalled();
});
expect($rootScope.focus).toHaveBeenCalledOnce();
}));
it('should call the listener synchronously inside of $apply if outside of $apply',
inject(function($rootScope, $compile) {
element = $compile('<input type="text" ng-focus="focus()" ng-model="value">')($rootScope);
$rootScope.focus = jasmine.createSpy('focus').andCallFake(function() {
$rootScope.value = 'newValue';
});
element.triggerHandler('focus');
expect($rootScope.focus).toHaveBeenCalledOnce();
expect(element.val()).toBe('newValue');
}));
});
describe('blur', function() {
it('should call the listener asynchronously during $apply',
inject(function($rootScope, $compile) {
element = $compile('<input type="text" ng-blur="blur()">')($rootScope);
$rootScope.blur = jasmine.createSpy('blur');
$rootScope.$apply(function() {
element.triggerHandler('blur');
expect($rootScope.blur).not.toHaveBeenCalled();
});
expect($rootScope.blur).toHaveBeenCalledOnce();
}));
it('should call the listener synchronously inside of $apply if outside of $apply',
inject(function($rootScope, $compile) {
element = $compile('<input type="text" ng-blur="blur()" ng-model="value">')($rootScope);
$rootScope.blur = jasmine.createSpy('blur').andCallFake(function() {
$rootScope.value = 'newValue';
});
element.triggerHandler('blur');
expect($rootScope.blur).toHaveBeenCalledOnce();
expect(element.val()).toBe('newValue');
}));
});
});