forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathngChangeSpec.js
54 lines (35 loc) · 1.62 KB
/
ngChangeSpec.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
'use strict';
/* globals generateInputCompilerHelper: false */
describe('ngChange', function() {
var helper = {}, $rootScope;
generateInputCompilerHelper(helper);
beforeEach(inject(function(_$rootScope_) {
$rootScope = _$rootScope_;
}));
it('should $eval expression after new value is set in the model', function() {
helper.compileInput('<input type="text" ng-model="value" ng-change="change()" />');
$rootScope.change = jasmine.createSpy('change').and.callFake(function() {
expect($rootScope.value).toBe('new value');
});
helper.changeInputValueTo('new value');
expect($rootScope.change).toHaveBeenCalledOnce();
});
it('should not $eval the expression if changed from model', function() {
helper.compileInput('<input type="text" ng-model="value" ng-change="change()" />');
$rootScope.change = jasmine.createSpy('change');
$rootScope.$apply('value = true');
expect($rootScope.change).not.toHaveBeenCalled();
});
it('should $eval ngChange expression on checkbox', function() {
var inputElm = helper.compileInput('<input type="checkbox" ng-model="foo" ng-change="changeFn()">');
$rootScope.changeFn = jasmine.createSpy('changeFn');
expect($rootScope.changeFn).not.toHaveBeenCalled();
browserTrigger(inputElm, 'click');
expect($rootScope.changeFn).toHaveBeenCalledOnce();
});
it('should be able to change the model and via that also update the view', function() {
var inputElm = helper.compileInput('<input type="text" ng-model="value" ng-change="value=\'b\'" />');
helper.changeInputValueTo('a');
expect(inputElm.val()).toBe('b');
});
});