@angular-wave/angular.ts 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +1 -0
- package/.eslintrc.cjs +29 -0
- package/.github/workflows/playwright.yml +27 -0
- package/CHANGELOG.md +17974 -0
- package/CODE_OF_CONDUCT.md +3 -0
- package/CONTRIBUTING.md +246 -0
- package/DEVELOPERS.md +488 -0
- package/LICENSE +22 -0
- package/Makefile +31 -0
- package/README.md +115 -0
- package/RELEASE.md +98 -0
- package/SECURITY.md +16 -0
- package/TRIAGING.md +135 -0
- package/css/angular.css +22 -0
- package/dist/angular-ts.cjs.js +36843 -0
- package/dist/angular-ts.esm.js +36841 -0
- package/dist/angular-ts.umd.js +36848 -0
- package/dist/build/angular-animate.js +4272 -0
- package/dist/build/angular-aria.js +426 -0
- package/dist/build/angular-message-format.js +1072 -0
- package/dist/build/angular-messages.js +829 -0
- package/dist/build/angular-mocks.js +3757 -0
- package/dist/build/angular-parse-ext.js +1275 -0
- package/dist/build/angular-resource.js +911 -0
- package/dist/build/angular-route.js +1266 -0
- package/dist/build/angular-sanitize.js +891 -0
- package/dist/build/angular-touch.js +368 -0
- package/dist/build/angular.js +36600 -0
- package/e2e/unit.spec.ts +15 -0
- package/images/android-chrome-192x192.png +0 -0
- package/images/android-chrome-512x512.png +0 -0
- package/images/apple-touch-icon.png +0 -0
- package/images/favicon-16x16.png +0 -0
- package/images/favicon-32x32.png +0 -0
- package/images/favicon.ico +0 -0
- package/images/site.webmanifest +1 -0
- package/index.html +104 -0
- package/package.json +47 -0
- package/playwright.config.ts +78 -0
- package/public/circle.html +1 -0
- package/public/my_child_directive.html +1 -0
- package/public/my_directive.html +1 -0
- package/public/my_other_directive.html +1 -0
- package/public/test.html +1 -0
- package/rollup.config.js +31 -0
- package/src/animations/animateCache.js +55 -0
- package/src/animations/animateChildrenDirective.js +105 -0
- package/src/animations/animateCss.js +1139 -0
- package/src/animations/animateCssDriver.js +291 -0
- package/src/animations/animateJs.js +367 -0
- package/src/animations/animateJsDriver.js +67 -0
- package/src/animations/animateQueue.js +851 -0
- package/src/animations/animation.js +506 -0
- package/src/animations/module.js +779 -0
- package/src/animations/ngAnimateSwap.js +119 -0
- package/src/animations/rafScheduler.js +50 -0
- package/src/animations/shared.js +378 -0
- package/src/constants.js +20 -0
- package/src/core/animate.js +845 -0
- package/src/core/animateCss.js +73 -0
- package/src/core/animateRunner.js +195 -0
- package/src/core/attributes.js +199 -0
- package/src/core/cache.js +45 -0
- package/src/core/compile.js +4727 -0
- package/src/core/controller.js +225 -0
- package/src/core/exceptionHandler.js +63 -0
- package/src/core/filter.js +146 -0
- package/src/core/interpolate.js +442 -0
- package/src/core/interval.js +188 -0
- package/src/core/intervalFactory.js +57 -0
- package/src/core/location.js +1086 -0
- package/src/core/parser/parse.js +2562 -0
- package/src/core/parser/parse.md +13 -0
- package/src/core/q.js +746 -0
- package/src/core/rootScope.js +1596 -0
- package/src/core/sanitizeUri.js +85 -0
- package/src/core/sce.js +1161 -0
- package/src/core/taskTrackerFactory.js +125 -0
- package/src/core/timeout.js +121 -0
- package/src/core/urlUtils.js +187 -0
- package/src/core/utils.js +1349 -0
- package/src/directive/a.js +37 -0
- package/src/directive/attrs.js +283 -0
- package/src/directive/bind.js +51 -0
- package/src/directive/bind.md +142 -0
- package/src/directive/change.js +12 -0
- package/src/directive/change.md +25 -0
- package/src/directive/cloak.js +12 -0
- package/src/directive/cloak.md +24 -0
- package/src/directive/events.js +75 -0
- package/src/directive/events.md +166 -0
- package/src/directive/form.js +725 -0
- package/src/directive/init.js +15 -0
- package/src/directive/init.md +41 -0
- package/src/directive/input.js +1783 -0
- package/src/directive/list.js +46 -0
- package/src/directive/list.md +22 -0
- package/src/directive/ngClass.js +249 -0
- package/src/directive/ngController.js +64 -0
- package/src/directive/ngCsp.js +82 -0
- package/src/directive/ngIf.js +134 -0
- package/src/directive/ngInclude.js +217 -0
- package/src/directive/ngModel.js +1356 -0
- package/src/directive/ngModelOptions.js +509 -0
- package/src/directive/ngOptions.js +670 -0
- package/src/directive/ngRef.js +90 -0
- package/src/directive/ngRepeat.js +650 -0
- package/src/directive/ngShowHide.js +255 -0
- package/src/directive/ngSwitch.js +178 -0
- package/src/directive/ngTransclude.js +98 -0
- package/src/directive/non-bindable.js +11 -0
- package/src/directive/non-bindable.md +17 -0
- package/src/directive/script.js +30 -0
- package/src/directive/select.js +624 -0
- package/src/directive/style.js +25 -0
- package/src/directive/style.md +23 -0
- package/src/directive/validators.js +329 -0
- package/src/exts/aria.js +544 -0
- package/src/exts/messages.js +852 -0
- package/src/filters/filter.js +207 -0
- package/src/filters/filter.md +69 -0
- package/src/filters/filters.js +239 -0
- package/src/filters/json.md +16 -0
- package/src/filters/limit-to.js +43 -0
- package/src/filters/limit-to.md +19 -0
- package/src/filters/order-by.js +183 -0
- package/src/filters/order-by.md +83 -0
- package/src/index.js +13 -0
- package/src/injector.js +1034 -0
- package/src/jqLite.js +1117 -0
- package/src/loader.js +1320 -0
- package/src/public.js +215 -0
- package/src/routeToRegExp.js +41 -0
- package/src/services/anchorScroll.js +135 -0
- package/src/services/browser.js +321 -0
- package/src/services/cacheFactory.js +398 -0
- package/src/services/cookieReader.js +72 -0
- package/src/services/document.js +64 -0
- package/src/services/http.js +1537 -0
- package/src/services/httpBackend.js +206 -0
- package/src/services/log.js +160 -0
- package/src/services/templateRequest.js +139 -0
- package/test/angular.spec.js +2153 -0
- package/test/aria/aria.spec.js +1245 -0
- package/test/binding.spec.js +504 -0
- package/test/build-test.html +14 -0
- package/test/injector.spec.js +2327 -0
- package/test/jasmine/jasmine-5.1.2/boot0.js +65 -0
- package/test/jasmine/jasmine-5.1.2/boot1.js +133 -0
- package/test/jasmine/jasmine-5.1.2/jasmine-html.js +963 -0
- package/test/jasmine/jasmine-5.1.2/jasmine.css +320 -0
- package/test/jasmine/jasmine-5.1.2/jasmine.js +10824 -0
- package/test/jasmine/jasmine-5.1.2/jasmine_favicon.png +0 -0
- package/test/jasmine/jasmine-browser.json +17 -0
- package/test/jasmine/jasmine.json +9 -0
- package/test/jqlite.spec.js +2133 -0
- package/test/loader.spec.js +219 -0
- package/test/messages/messages.spec.js +1146 -0
- package/test/min-err.spec.js +174 -0
- package/test/mock-test.html +13 -0
- package/test/module-test.html +15 -0
- package/test/ng/anomate.spec.js +606 -0
- package/test/ng/cache-factor.spec.js +334 -0
- package/test/ng/compile.spec.js +17956 -0
- package/test/ng/controller-provider.spec.js +227 -0
- package/test/ng/cookie-reader.spec.js +98 -0
- package/test/ng/directive/a.spec.js +192 -0
- package/test/ng/directive/bind.spec.js +334 -0
- package/test/ng/directive/boolean.spec.js +136 -0
- package/test/ng/directive/change.spec.js +71 -0
- package/test/ng/directive/class.spec.js +858 -0
- package/test/ng/directive/click.spec.js +38 -0
- package/test/ng/directive/cloak.spec.js +44 -0
- package/test/ng/directive/constoller.spec.js +194 -0
- package/test/ng/directive/element-style.spec.js +92 -0
- package/test/ng/directive/event.spec.js +282 -0
- package/test/ng/directive/form.spec.js +1518 -0
- package/test/ng/directive/href.spec.js +143 -0
- package/test/ng/directive/if.spec.js +402 -0
- package/test/ng/directive/include.spec.js +828 -0
- package/test/ng/directive/init.spec.js +68 -0
- package/test/ng/directive/input.spec.js +3810 -0
- package/test/ng/directive/list.spec.js +170 -0
- package/test/ng/directive/model-options.spec.js +1008 -0
- package/test/ng/directive/model.spec.js +1905 -0
- package/test/ng/directive/non-bindable.spec.js +55 -0
- package/test/ng/directive/options.spec.js +3583 -0
- package/test/ng/directive/ref.spec.js +575 -0
- package/test/ng/directive/repeat.spec.js +1675 -0
- package/test/ng/directive/script.spec.js +52 -0
- package/test/ng/directive/scrset.spec.js +67 -0
- package/test/ng/directive/select.spec.js +2541 -0
- package/test/ng/directive/show-hide.spec.js +253 -0
- package/test/ng/directive/src.spec.js +157 -0
- package/test/ng/directive/style.spec.js +178 -0
- package/test/ng/directive/switch.spec.js +647 -0
- package/test/ng/directive/validators.spec.js +717 -0
- package/test/ng/document.spec.js +52 -0
- package/test/ng/filter/filter.spec.js +714 -0
- package/test/ng/filter/filters.spec.js +35 -0
- package/test/ng/filter/limit-to.spec.js +251 -0
- package/test/ng/filter/order-by.spec.js +891 -0
- package/test/ng/filter.spec.js +149 -0
- package/test/ng/http-backend.spec.js +398 -0
- package/test/ng/http.spec.js +4071 -0
- package/test/ng/interpolate.spec.js +642 -0
- package/test/ng/interval.spec.js +343 -0
- package/test/ng/location.spec.js +3488 -0
- package/test/ng/on.spec.js +229 -0
- package/test/ng/parse.spec.js +4655 -0
- package/test/ng/prop.spec.js +805 -0
- package/test/ng/q.spec.js +2904 -0
- package/test/ng/root-element.spec.js +16 -0
- package/test/ng/sanitize-uri.spec.js +249 -0
- package/test/ng/sce.spec.js +660 -0
- package/test/ng/scope.spec.js +3442 -0
- package/test/ng/template-request.spec.js +236 -0
- package/test/ng/timeout.spec.js +351 -0
- package/test/ng/url-utils.spec.js +156 -0
- package/test/ng/utils.spec.js +144 -0
- package/test/original-test.html +21 -0
- package/test/public.spec.js +34 -0
- package/test/sanitize/bing-html.spec.js +36 -0
- package/test/server/express.js +158 -0
- package/test/test-utils.js +11 -0
- package/tsconfig.json +17 -0
- package/types/angular.d.ts +138 -0
- package/types/global.d.ts +9 -0
- package/types/index.d.ts +2357 -0
- package/types/jqlite.d.ts +558 -0
- package/vite.config.js +14 -0
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import { publishExternalAPI } from "../../../src/public";
|
|
2
|
+
import { createInjector } from "../../../src/injector";
|
|
3
|
+
import { dealoc } from "../../../src/jqLite";
|
|
4
|
+
|
|
5
|
+
describe("ng-bind", () => {
|
|
6
|
+
let $rootScope;
|
|
7
|
+
let $compile;
|
|
8
|
+
let element;
|
|
9
|
+
let scope;
|
|
10
|
+
let $sce;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
publishExternalAPI().decorator("$exceptionHandler", function () {
|
|
14
|
+
return (exception, cause) => {
|
|
15
|
+
throw new Error(exception.message);
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
createInjector(["ng"]).invoke((_$rootScope_, _$compile_, _$sce_) => {
|
|
19
|
+
$rootScope = _$rootScope_;
|
|
20
|
+
$compile = _$compile_;
|
|
21
|
+
$sce = _$sce_;
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
dealoc(element);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe("ngBind", () => {
|
|
30
|
+
it("should set text", () => {
|
|
31
|
+
element = $compile('<div ng-bind="a"></div>')($rootScope);
|
|
32
|
+
expect(element.text()).toEqual("");
|
|
33
|
+
$rootScope.a = "misko";
|
|
34
|
+
$rootScope.$digest();
|
|
35
|
+
expect(element.text()).toEqual("misko");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("should set text to blank if undefined", () => {
|
|
39
|
+
element = $compile('<div ng-bind="a"></div>')($rootScope);
|
|
40
|
+
$rootScope.a = "misko";
|
|
41
|
+
$rootScope.$digest();
|
|
42
|
+
expect(element.text()).toEqual("misko");
|
|
43
|
+
$rootScope.a = undefined;
|
|
44
|
+
$rootScope.$digest();
|
|
45
|
+
expect(element.text()).toEqual("");
|
|
46
|
+
$rootScope.a = null;
|
|
47
|
+
$rootScope.$digest();
|
|
48
|
+
expect(element.text()).toEqual("");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("should suppress rendering of falsy values", () => {
|
|
52
|
+
element = $compile(
|
|
53
|
+
'<div><span ng-bind="null"></span>' +
|
|
54
|
+
'<span ng-bind="undefined"></span>' +
|
|
55
|
+
"<span ng-bind=\"''\"></span>-" +
|
|
56
|
+
'<span ng-bind="0"></span>' +
|
|
57
|
+
'<span ng-bind="false"></span>' +
|
|
58
|
+
"</div>",
|
|
59
|
+
)($rootScope);
|
|
60
|
+
$rootScope.$digest();
|
|
61
|
+
expect(element.text()).toEqual("-0false");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
[
|
|
65
|
+
[{ a: 1 }, '{"a":1}'],
|
|
66
|
+
[true, "true"],
|
|
67
|
+
[false, "false"],
|
|
68
|
+
].forEach((prop) => {
|
|
69
|
+
it("should jsonify $prop", () => {
|
|
70
|
+
() => {
|
|
71
|
+
$rootScope.value = prop[0];
|
|
72
|
+
element = $compile('<div ng-bind="value"></div>')($rootScope);
|
|
73
|
+
$rootScope.$digest();
|
|
74
|
+
expect(element.text()).toEqual(prop[1]);
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("should use custom toString when present", () => {
|
|
80
|
+
$rootScope.value = {
|
|
81
|
+
toString() {
|
|
82
|
+
return "foo";
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
element = $compile('<div ng-bind="value"></div>')($rootScope);
|
|
86
|
+
$rootScope.$digest();
|
|
87
|
+
expect(element.text()).toEqual("foo");
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("should NOT use toString on array objects", () => {
|
|
91
|
+
$rootScope.value = [];
|
|
92
|
+
element = $compile('<div ng-bind="value"></div>')($rootScope);
|
|
93
|
+
$rootScope.$digest();
|
|
94
|
+
expect(element.text()).toEqual("[]");
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("should NOT use toString on Date objects", () => {
|
|
98
|
+
$rootScope.value = new Date(2014, 10, 10, 0, 0, 0);
|
|
99
|
+
element = $compile('<div ng-bind="value"></div>')($rootScope);
|
|
100
|
+
$rootScope.$digest();
|
|
101
|
+
expect(element.text()).toBe(JSON.stringify($rootScope.value));
|
|
102
|
+
expect(element.text()).not.toEqual($rootScope.value.toString());
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("should one-time bind if the expression starts with two colons", () => {
|
|
106
|
+
element = $compile('<div ng-bind="::a"></div>')($rootScope);
|
|
107
|
+
$rootScope.a = "lucas";
|
|
108
|
+
expect($rootScope.$$watchers.length).toEqual(1);
|
|
109
|
+
$rootScope.$digest();
|
|
110
|
+
expect(element.text()).toEqual("lucas");
|
|
111
|
+
expect($rootScope.$$watchers.length).toEqual(0);
|
|
112
|
+
$rootScope.a = undefined;
|
|
113
|
+
$rootScope.$digest();
|
|
114
|
+
expect(element.text()).toEqual("lucas");
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("should be possible to bind to a new value within the same $digest", () => {
|
|
118
|
+
element = $compile('<div ng-bind="::a"></div>')($rootScope);
|
|
119
|
+
$rootScope.$watch("a", (newVal) => {
|
|
120
|
+
if (newVal === "foo") {
|
|
121
|
+
$rootScope.a = "bar";
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
$rootScope.a = "foo";
|
|
125
|
+
$rootScope.$digest();
|
|
126
|
+
expect(element.text()).toEqual("bar");
|
|
127
|
+
$rootScope.a = undefined;
|
|
128
|
+
$rootScope.$digest();
|
|
129
|
+
expect(element.text()).toEqual("bar");
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("should remove the binding if the value is defined at the end of a $digest loop", () => {
|
|
133
|
+
element = $compile('<div ng-bind="::a"></div>')($rootScope);
|
|
134
|
+
$rootScope.$watch("a", (newVal) => {
|
|
135
|
+
if (newVal === "foo") {
|
|
136
|
+
$rootScope.a = undefined;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
$rootScope.a = "foo";
|
|
140
|
+
$rootScope.$digest();
|
|
141
|
+
expect(element.text()).toEqual("");
|
|
142
|
+
$rootScope.a = "bar";
|
|
143
|
+
$rootScope.$digest();
|
|
144
|
+
expect(element.text()).toEqual("bar");
|
|
145
|
+
$rootScope.a = "man";
|
|
146
|
+
$rootScope.$digest();
|
|
147
|
+
expect(element.text()).toEqual("bar");
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe("ngBindTemplate", () => {
|
|
152
|
+
it("should ngBindTemplate", () => {
|
|
153
|
+
element = $compile('<div ng-bind-template="Hello {{name}}!"></div>')(
|
|
154
|
+
$rootScope,
|
|
155
|
+
);
|
|
156
|
+
$rootScope.name = "Misko";
|
|
157
|
+
$rootScope.$digest();
|
|
158
|
+
expect(element.text()).toEqual("Hello Misko!");
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("should one-time bind the expressions that start with ::", () => {
|
|
162
|
+
element = $compile(
|
|
163
|
+
'<div ng-bind-template="{{::hello}} {{::name}}!"></div>',
|
|
164
|
+
)($rootScope);
|
|
165
|
+
$rootScope.name = "Misko";
|
|
166
|
+
expect($rootScope.$$watchers.length).toEqual(2);
|
|
167
|
+
$rootScope.$digest();
|
|
168
|
+
expect(element.text()).toEqual(" Misko!");
|
|
169
|
+
expect($rootScope.$$watchers.length).toEqual(1);
|
|
170
|
+
$rootScope.hello = "Hello";
|
|
171
|
+
$rootScope.name = "Lucas";
|
|
172
|
+
$rootScope.$digest();
|
|
173
|
+
expect(element.text()).toEqual("Hello Misko!");
|
|
174
|
+
expect($rootScope.$$watchers.length).toEqual(0);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("should render object as JSON ignore $$", () => {
|
|
178
|
+
element = $compile('<pre>{{ {key:"value", $$key:"hide"} }}</pre>')(
|
|
179
|
+
$rootScope,
|
|
180
|
+
);
|
|
181
|
+
$rootScope.$digest();
|
|
182
|
+
|
|
183
|
+
expect(JSON.parse(element.text())).toEqual({ key: "value" });
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
describe("ngBindHtml", () => {
|
|
188
|
+
it("should complain about accidental use of interpolation", () => {
|
|
189
|
+
expect(() => {
|
|
190
|
+
$compile('<div ng-bind-html="{{myHtml}}"></div>');
|
|
191
|
+
$rootScope.$digest();
|
|
192
|
+
}).toThrowError(/syntax/);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
describe("SCE disabled", () => {
|
|
196
|
+
beforeEach(() => {
|
|
197
|
+
createInjector([
|
|
198
|
+
"ng",
|
|
199
|
+
($sceProvider) => {
|
|
200
|
+
$sceProvider.enabled(false);
|
|
201
|
+
},
|
|
202
|
+
]).invoke((_$rootScope_, _$compile_, _$sce_) => {
|
|
203
|
+
$rootScope = _$rootScope_;
|
|
204
|
+
$compile = _$compile_;
|
|
205
|
+
$sce = _$sce_;
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
afterEach(() => dealoc(element));
|
|
210
|
+
|
|
211
|
+
it("should set html", () => {
|
|
212
|
+
element = $compile('<div ng-bind-html="html"></div>')($rootScope);
|
|
213
|
+
$rootScope.html = '<div onclick="">hello</div>';
|
|
214
|
+
$rootScope.$digest();
|
|
215
|
+
expect(element.html()).toEqual('<div onclick="">hello</div>');
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it("should update html", () => {
|
|
219
|
+
element = $compile('<div ng-bind-html="html"></div>')($rootScope);
|
|
220
|
+
$rootScope.html = "hello";
|
|
221
|
+
$rootScope.$digest();
|
|
222
|
+
expect(element.html()).toEqual("hello");
|
|
223
|
+
$rootScope.html = "goodbye";
|
|
224
|
+
$rootScope.$digest();
|
|
225
|
+
expect(element.html()).toEqual("goodbye");
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it("should one-time bind if the expression starts with two colons", () => {
|
|
229
|
+
element = $compile('<div ng-bind-html="::html"></div>')($rootScope);
|
|
230
|
+
$rootScope.html = '<div onclick="">hello</div>';
|
|
231
|
+
expect($rootScope.$$watchers.length).toEqual(1);
|
|
232
|
+
$rootScope.$digest();
|
|
233
|
+
expect(element.text()).toEqual("hello");
|
|
234
|
+
expect($rootScope.$$watchers.length).toEqual(0);
|
|
235
|
+
$rootScope.html = '<div onclick="">hello</div>';
|
|
236
|
+
$rootScope.$digest();
|
|
237
|
+
expect(element.text()).toEqual("hello");
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
describe("SCE enabled", () => {
|
|
242
|
+
beforeEach(() => {
|
|
243
|
+
createInjector([
|
|
244
|
+
"ng",
|
|
245
|
+
($sceProvider) => {
|
|
246
|
+
$sceProvider.enabled(true);
|
|
247
|
+
},
|
|
248
|
+
]).invoke((_$rootScope_, _$compile_, _$sce_) => {
|
|
249
|
+
$rootScope = _$rootScope_;
|
|
250
|
+
$compile = _$compile_;
|
|
251
|
+
$sce = _$sce_;
|
|
252
|
+
});
|
|
253
|
+
scope = $rootScope.$new();
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
afterEach(() => dealoc(element));
|
|
257
|
+
|
|
258
|
+
it("should set html for trusted values", () => {
|
|
259
|
+
element = $compile('<div ng-bind-html="html"></div>')($rootScope);
|
|
260
|
+
$rootScope.html = $sce.trustAsHtml('<div onclick="">hello</div>');
|
|
261
|
+
$rootScope.$digest();
|
|
262
|
+
expect(element.html()).toEqual('<div onclick="">hello</div>');
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it("should update html", () => {
|
|
266
|
+
element = $compile('<div ng-bind-html="html"></div>')(scope);
|
|
267
|
+
scope.html = $sce.trustAsHtml("hello");
|
|
268
|
+
scope.$digest();
|
|
269
|
+
expect(element.html()).toEqual("hello");
|
|
270
|
+
scope.html = $sce.trustAsHtml("goodbye");
|
|
271
|
+
scope.$digest();
|
|
272
|
+
expect(element.html()).toEqual("goodbye");
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("should not cause infinite recursion for trustAsHtml object watches", () => {
|
|
276
|
+
// Ref: https://github.com/angular/angular.js/issues/3932
|
|
277
|
+
// If the binding is a function that creates a new value on every call via trustAs, we'll
|
|
278
|
+
// trigger an infinite digest if we don't take care of it.
|
|
279
|
+
element = $compile('<div ng-bind-html="getHtml()"></div>')($rootScope);
|
|
280
|
+
$rootScope.getHtml = function () {
|
|
281
|
+
return $sce.trustAsHtml('<div onclick="">hello</div>');
|
|
282
|
+
};
|
|
283
|
+
$rootScope.$digest();
|
|
284
|
+
expect(element.html()).toEqual('<div onclick="">hello</div>');
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it("should handle custom $sce objects", () => {
|
|
288
|
+
function MySafeHtml(val) {
|
|
289
|
+
this.val = val;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
let injector = createInjector([
|
|
293
|
+
"ng",
|
|
294
|
+
function ($provide) {
|
|
295
|
+
$provide.decorator("$sce", ($delegate) => {
|
|
296
|
+
$delegate.trustAsHtml = function (html) {
|
|
297
|
+
return new MySafeHtml(html);
|
|
298
|
+
};
|
|
299
|
+
$delegate.getTrustedHtml = function (mySafeHtml) {
|
|
300
|
+
return mySafeHtml.val;
|
|
301
|
+
};
|
|
302
|
+
$delegate.valueOf = function (v) {
|
|
303
|
+
return v instanceof MySafeHtml ? v.val : v;
|
|
304
|
+
};
|
|
305
|
+
return $delegate;
|
|
306
|
+
});
|
|
307
|
+
},
|
|
308
|
+
]).invoke((_$rootScope_, _$compile_, _$sce_) => {
|
|
309
|
+
$rootScope = _$rootScope_.$new();
|
|
310
|
+
$compile = _$compile_;
|
|
311
|
+
$sce = _$sce_;
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
() => {
|
|
315
|
+
// Ref: https://github.com/angular/angular.js/issues/14526
|
|
316
|
+
// Previous code used toString for change detection, which fails for custom objects
|
|
317
|
+
// that don't override toString.
|
|
318
|
+
element = $compile('<div ng-bind-html="getHtml()"></div>')(
|
|
319
|
+
$rootScope,
|
|
320
|
+
);
|
|
321
|
+
let html = "hello";
|
|
322
|
+
$rootScope.getHtml = function () {
|
|
323
|
+
return $sce.trustAsHtml(html);
|
|
324
|
+
};
|
|
325
|
+
$rootScope.$digest();
|
|
326
|
+
expect(element.html()).toEqual("hello");
|
|
327
|
+
html = "goodbye";
|
|
328
|
+
$rootScope.$digest();
|
|
329
|
+
expect(element.html()).toEqual("goodbye");
|
|
330
|
+
};
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
});
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { publishExternalAPI } from "../../../src/public";
|
|
2
|
+
import { createInjector } from "../../../src/injector";
|
|
3
|
+
|
|
4
|
+
describe("boolean attr directives", () => {
|
|
5
|
+
let element, $rootScope, $compile, $document, $rootElement;
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
publishExternalAPI();
|
|
9
|
+
createInjector([
|
|
10
|
+
"ng",
|
|
11
|
+
($provide) => {
|
|
12
|
+
$provide.value("$rootElement", window.document.body);
|
|
13
|
+
},
|
|
14
|
+
]).invoke((_$compile_, _$rootScope_, _$rootElement_) => {
|
|
15
|
+
$compile = _$compile_;
|
|
16
|
+
$rootScope = _$rootScope_;
|
|
17
|
+
$rootElement = _$rootElement_;
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
// dealoc(element);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("should properly evaluate 0 as false", () => {
|
|
26
|
+
// jQuery does not treat 0 as false, when setting attr()
|
|
27
|
+
element = $compile('<button ng-disabled="isDisabled">Button</button>')(
|
|
28
|
+
$rootScope,
|
|
29
|
+
);
|
|
30
|
+
$rootScope.isDisabled = 0;
|
|
31
|
+
$rootScope.$digest();
|
|
32
|
+
expect(element.attr("disabled")).toBeFalsy();
|
|
33
|
+
$rootScope.isDisabled = 1;
|
|
34
|
+
$rootScope.$digest();
|
|
35
|
+
expect(element.attr("disabled")).toBeTruthy();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("should bind disabled", () => {
|
|
39
|
+
element = $compile('<button ng-disabled="isDisabled">Button</button>')(
|
|
40
|
+
$rootScope,
|
|
41
|
+
);
|
|
42
|
+
$rootScope.isDisabled = false;
|
|
43
|
+
$rootScope.$digest();
|
|
44
|
+
expect(element.attr("disabled")).toBeFalsy();
|
|
45
|
+
$rootScope.isDisabled = true;
|
|
46
|
+
$rootScope.$digest();
|
|
47
|
+
expect(element.attr("disabled")).toBeTruthy();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("should bind checked", () => {
|
|
51
|
+
element = $compile('<input type="checkbox" ng-checked="isChecked" />')(
|
|
52
|
+
$rootScope,
|
|
53
|
+
);
|
|
54
|
+
$rootScope.isChecked = false;
|
|
55
|
+
$rootScope.$digest();
|
|
56
|
+
expect(element.attr("checked")).toBeFalsy();
|
|
57
|
+
$rootScope.isChecked = true;
|
|
58
|
+
$rootScope.$digest();
|
|
59
|
+
expect(element.attr("checked")).toBeTruthy();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("should not bind checked when ngModel is present", () => {
|
|
63
|
+
// test for https://github.com/angular/angular.js/issues/10662
|
|
64
|
+
element = $compile(
|
|
65
|
+
'<input type="checkbox" ng-model="value" ng-false-value="\'false\'" ' +
|
|
66
|
+
'ng-true-value="\'true\'" ng-checked="value" />',
|
|
67
|
+
)($rootScope);
|
|
68
|
+
|
|
69
|
+
$rootScope.value = "true";
|
|
70
|
+
$rootScope.$digest();
|
|
71
|
+
expect(element[0].checked).toBe(true);
|
|
72
|
+
|
|
73
|
+
element[0].checked = !element[0].checked;
|
|
74
|
+
element[0].dispatchEvent(new Event("change"));
|
|
75
|
+
expect(element[0].checked).toBe(false);
|
|
76
|
+
expect($rootScope.value).toBe("false");
|
|
77
|
+
element[0].checked = !element[0].checked;
|
|
78
|
+
element[0].dispatchEvent(new Event("change"));
|
|
79
|
+
expect(element[0].checked).toBe(true);
|
|
80
|
+
expect($rootScope.value).toBe("true");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("should bind selected", () => {
|
|
84
|
+
element = $compile(
|
|
85
|
+
'<select><option value=""></option><option ng-selected="isSelected">Greetings!</option></select>',
|
|
86
|
+
)($rootScope);
|
|
87
|
+
$rootScope.isSelected = false;
|
|
88
|
+
$rootScope.$digest();
|
|
89
|
+
expect(element.children()[1].selected).toBeFalsy();
|
|
90
|
+
$rootScope.isSelected = true;
|
|
91
|
+
$rootScope.$digest();
|
|
92
|
+
expect(element.children()[1].selected).toBeTruthy();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("should bind readonly", () => {
|
|
96
|
+
element = $compile('<input type="text" ng-readonly="isReadonly" />')(
|
|
97
|
+
$rootScope,
|
|
98
|
+
);
|
|
99
|
+
$rootScope.isReadonly = false;
|
|
100
|
+
$rootScope.$digest();
|
|
101
|
+
expect(element.attr("readOnly")).toBeFalsy();
|
|
102
|
+
$rootScope.isReadonly = true;
|
|
103
|
+
$rootScope.$digest();
|
|
104
|
+
expect(element.attr("readOnly")).toBeTruthy();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("should bind open", () => {
|
|
108
|
+
element = $compile('<details ng-open="isOpen"></details>')($rootScope);
|
|
109
|
+
$rootScope.isOpen = false;
|
|
110
|
+
$rootScope.$digest();
|
|
111
|
+
expect(element.attr("open")).toBeFalsy();
|
|
112
|
+
$rootScope.isOpen = true;
|
|
113
|
+
$rootScope.$digest();
|
|
114
|
+
expect(element.attr("open")).toBeTruthy();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe("multiple", () => {
|
|
118
|
+
it("should NOT bind to multiple via ngMultiple", () => {
|
|
119
|
+
element = $compile('<select ng-multiple="isMultiple"></select>')(
|
|
120
|
+
$rootScope,
|
|
121
|
+
);
|
|
122
|
+
$rootScope.isMultiple = false;
|
|
123
|
+
$rootScope.$digest();
|
|
124
|
+
expect(element.attr("multiple")).toBeFalsy();
|
|
125
|
+
$rootScope.isMultiple = "multiple";
|
|
126
|
+
$rootScope.$digest();
|
|
127
|
+
expect(element.attr("multiple")).toBeFalsy(); // ignore
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("should throw an exception if binding to multiple attribute", () => {
|
|
131
|
+
expect(() => {
|
|
132
|
+
$compile('<select multiple="{{isMultiple}}"></select>');
|
|
133
|
+
}).toThrowError(/selmulti/);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { createInjector } from "../../../src/injector";
|
|
2
|
+
import { dealoc } from "../../../src/jqLite";
|
|
3
|
+
import { publishExternalAPI } from "../../../src/public";
|
|
4
|
+
|
|
5
|
+
describe("ngChange", () => {
|
|
6
|
+
let injector;
|
|
7
|
+
let el;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
publishExternalAPI();
|
|
11
|
+
injector = createInjector(["ng"]);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
afterEach(() => dealoc(el));
|
|
15
|
+
|
|
16
|
+
it("should $eval expression after new value is set in the model", () => {
|
|
17
|
+
injector.invoke(($compile, $rootScope) => {
|
|
18
|
+
el = $compile(
|
|
19
|
+
'<input type="text" ng-model="value" ng-change="change()" />',
|
|
20
|
+
)($rootScope);
|
|
21
|
+
|
|
22
|
+
$rootScope.change = jasmine.createSpy("change").and.callFake(() => {
|
|
23
|
+
expect($rootScope.value).toBe("new value");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
el[0].setAttribute("value", "new value");
|
|
27
|
+
el[0].dispatchEvent(new Event("change"));
|
|
28
|
+
|
|
29
|
+
expect($rootScope.change).toHaveBeenCalled();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("should not $eval the expression if changed from model", () => {
|
|
34
|
+
injector.invoke(($compile, $rootScope) => {
|
|
35
|
+
el = $compile(
|
|
36
|
+
'<input type="text" ng-model="value" ng-change="change()" />',
|
|
37
|
+
)($rootScope);
|
|
38
|
+
|
|
39
|
+
$rootScope.change = jasmine.createSpy("change");
|
|
40
|
+
$rootScope.$apply("value = true");
|
|
41
|
+
|
|
42
|
+
expect($rootScope.change).not.toHaveBeenCalled();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("should $eval ngChange expression on checkbox", () => {
|
|
47
|
+
injector.invoke(($compile, $rootScope) => {
|
|
48
|
+
el = $compile(
|
|
49
|
+
'<input type="checkbox" ng-model="foo" ng-change="changeFn()">',
|
|
50
|
+
)($rootScope);
|
|
51
|
+
|
|
52
|
+
$rootScope.changeFn = jasmine.createSpy("changeFn");
|
|
53
|
+
expect($rootScope.changeFn).not.toHaveBeenCalled();
|
|
54
|
+
|
|
55
|
+
el[0].dispatchEvent(new Event("change"));
|
|
56
|
+
expect($rootScope.changeFn).toHaveBeenCalled();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should be able to change the model and via that also update the view", () => {
|
|
61
|
+
injector.invoke(($compile, $rootScope) => {
|
|
62
|
+
el = $compile(
|
|
63
|
+
'<input type="text" ng-model="value" ng-change="value=\'b\'" />',
|
|
64
|
+
)($rootScope);
|
|
65
|
+
|
|
66
|
+
el[0].setAttribute("value", "a");
|
|
67
|
+
el[0].dispatchEvent(new Event("change"));
|
|
68
|
+
expect(el.val()).toBe("b");
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
});
|