-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNgDirectiveWithScopeTrue.test.js
82 lines (65 loc) · 2.8 KB
/
NgDirectiveWithScopeTrue.test.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
describe('Inspector abilities for ngDirective({scope:true}) scope problems', function () {
"use strict";
var $rootScope, Inspector, InspectorHelpers;
beforeEach(function () {
module('inspector-test-helpers');
module('scope-aware');
});
beforeEach(inject(function (_$rootScope_, _Inspector_, _InspectorHelpers_) {
$rootScope = _$rootScope_;
Inspector = _Inspector_;
InspectorHelpers = _InspectorHelpers_;
}));
describe('when primitives are used', function() {
var $scope, element;
beforeEach(function() {
$scope = $rootScope.$new();
$scope.token = 'a';
element = InspectorHelpers.createDirective('directiveOwnScopeExplicitTrue', $scope);
});
afterEach(function() {
console.log(Inspector.inspect($scope));
});
it("shadows primitive properties", function () {
var input = element.find('input')[0];
var scope = angular.element(input).scope();
angular.element(input).val('AAA').triggerHandler('input');
$scope.$digest();
//it creates its own scope
expect(scope).not.toBe($scope);
expect(scope.$parent).toBe($scope);
//the value of token in the paren scope is still 'a' because the property has been shadowed
expect(scope.token).toBe('AAA');
expect($scope.token).toBe('a');
//additional tests (ng-scope-aware)
expect(scope).toHaveMembers('token');
expect(scope).not.toHaveInheritedMembers('token');
expect(scope).toShadow('token');
});
});
describe('when objects are used', function() {
var $scope, element;
beforeEach(function() {
$scope = $rootScope.$new();
$scope.tokenobj = { token : 'a' };
element = InspectorHelpers.createDirective('directiveOwnScopeExplicitTrueWithObject', $scope);
});
afterEach(function() {
console.log(Inspector.inspect($scope));
});
it("inherits objects and doesn't shadow them", function () {
var input = element.find('input')[0];
var scope = angular.element(input).scope();
angular.element(input).val('AAA').triggerHandler('input');
$scope.$digest();
//the value of token in the parent scope is 'AAA' because object is used
expect(scope.tokenobj.token).toBe('AAA');
expect($scope.tokenobj.token).toBe('AAA');
//additional tests (ng-scope-aware)
expect(scope).toHaveMembers('tokenobj');
expect(scope).toHaveInheritedMembers('tokenobj');
expect(scope).not.toShadow('token');
expect(scope).not.toShadow('tokenobj');
});
});
});