@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,236 @@
|
|
|
1
|
+
import { createInjector } from "../../src/injector";
|
|
2
|
+
import { publishExternalAPI } from "../../src/public";
|
|
3
|
+
|
|
4
|
+
describe("$templateRequest", () => {
|
|
5
|
+
let module, $rootScope, $templateRequest, $templateCache, $sce;
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
publishExternalAPI();
|
|
9
|
+
module = angular.module("test", ["ng"]);
|
|
10
|
+
let injector = createInjector(["test"]);
|
|
11
|
+
$rootScope = injector.get("$rootScope");
|
|
12
|
+
$templateRequest = injector.get("$templateRequest");
|
|
13
|
+
$templateCache = injector.get("$templateCache");
|
|
14
|
+
$sce = injector.get("$sce");
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe("provider", () => {
|
|
18
|
+
describe("httpOptions", () => {
|
|
19
|
+
it("should default to undefined and fallback to default $http options", () => {
|
|
20
|
+
let defaultHeader;
|
|
21
|
+
|
|
22
|
+
angular.module("test", [
|
|
23
|
+
"ng",
|
|
24
|
+
($templateRequestProvider) => {
|
|
25
|
+
expect($templateRequestProvider.httpOptions()).toBeUndefined();
|
|
26
|
+
},
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
createInjector(["test"]).invoke(
|
|
30
|
+
($templateRequest, $http, $templateCache) => {
|
|
31
|
+
spyOn($http, "get").and.callThrough();
|
|
32
|
+
|
|
33
|
+
$templateRequest("tpl.html");
|
|
34
|
+
|
|
35
|
+
expect($http.get).toHaveBeenCalledOnceWith("tpl.html", {
|
|
36
|
+
cache: $templateCache,
|
|
37
|
+
transformResponse: [],
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("should be configurable", () => {
|
|
44
|
+
function someTransform() {}
|
|
45
|
+
|
|
46
|
+
angular.module("test", [
|
|
47
|
+
"ng",
|
|
48
|
+
($templateRequestProvider) => {
|
|
49
|
+
// Configure the template request service to provide specific headers and transforms
|
|
50
|
+
$templateRequestProvider.httpOptions({
|
|
51
|
+
headers: { Accept: "moo" },
|
|
52
|
+
transformResponse: [someTransform],
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
]);
|
|
56
|
+
|
|
57
|
+
createInjector(["test"]).invoke(
|
|
58
|
+
($templateRequest, $http, $templateCache) => {
|
|
59
|
+
spyOn($http, "get").and.callThrough();
|
|
60
|
+
|
|
61
|
+
$templateRequest("tpl.html");
|
|
62
|
+
|
|
63
|
+
expect($http.get).toHaveBeenCalledOnceWith("tpl.html", {
|
|
64
|
+
cache: $templateCache,
|
|
65
|
+
transformResponse: [someTransform],
|
|
66
|
+
headers: { Accept: "moo" },
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("should be allow you to override the cache", () => {
|
|
73
|
+
const httpOptions = {};
|
|
74
|
+
|
|
75
|
+
angular.module("test", [
|
|
76
|
+
"ng",
|
|
77
|
+
($templateRequestProvider) => {
|
|
78
|
+
$templateRequestProvider.httpOptions(httpOptions);
|
|
79
|
+
},
|
|
80
|
+
]);
|
|
81
|
+
|
|
82
|
+
createInjector(["test"]).invoke(
|
|
83
|
+
($templateRequest, $http, $cacheFactory) => {
|
|
84
|
+
spyOn($http, "get").and.callThrough();
|
|
85
|
+
|
|
86
|
+
const customCache = $cacheFactory("customCache");
|
|
87
|
+
httpOptions.cache = customCache;
|
|
88
|
+
|
|
89
|
+
$templateRequest("tpl.html");
|
|
90
|
+
|
|
91
|
+
expect($http.get).toHaveBeenCalledOnceWith("tpl.html", {
|
|
92
|
+
cache: customCache,
|
|
93
|
+
transformResponse: [],
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("should download the provided template file", async () => {
|
|
102
|
+
let content;
|
|
103
|
+
await $templateRequest("/mock/div").then((html) => {
|
|
104
|
+
content = html;
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
$rootScope.$digest();
|
|
108
|
+
expect(content).toBe("<div>Hello</div>");
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("should cache the request to prevent extra downloads", async () => {
|
|
112
|
+
const content = [];
|
|
113
|
+
function tplRequestCb(html) {
|
|
114
|
+
content.push(html);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
await $templateRequest("/mock/div").then(tplRequestCb);
|
|
118
|
+
|
|
119
|
+
$templateRequest("/mock/div").then(tplRequestCb);
|
|
120
|
+
$rootScope.$digest();
|
|
121
|
+
|
|
122
|
+
expect(content[0]).toBe("<div>Hello</div>");
|
|
123
|
+
expect(content[1]).toBe("<div>Hello</div>");
|
|
124
|
+
expect($templateCache.get("/mock/div")).toBe("<div>Hello</div>");
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("should return the cached value on the first request", async () => {
|
|
128
|
+
spyOn($templateCache, "put").and.returnValue("_matias");
|
|
129
|
+
|
|
130
|
+
const content = [];
|
|
131
|
+
function tplRequestCb(html) {
|
|
132
|
+
content.push(html);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
await $templateRequest("tpl.html").then(tplRequestCb);
|
|
136
|
+
$rootScope.$digest();
|
|
137
|
+
|
|
138
|
+
expect(content[0]).toBe("_matias");
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("should call `$exceptionHandler` on request error", async () => {
|
|
142
|
+
let err;
|
|
143
|
+
await $templateRequest("/mock/404").catch((reason) => {
|
|
144
|
+
err = reason;
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
expect(err).toMatch(/tpload/);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("should not call `$exceptionHandler` when the template is empty", async () => {
|
|
151
|
+
const onError = jasmine.createSpy("onError");
|
|
152
|
+
await $templateRequest("/mock/empty").catch(onError);
|
|
153
|
+
$rootScope.$digest();
|
|
154
|
+
|
|
155
|
+
expect(onError).not.toHaveBeenCalled();
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("should accept empty templates and refuse null or undefined templates in cache", () => {
|
|
159
|
+
// Will throw on any template not in cache.
|
|
160
|
+
spyOn($sce, "getTrustedResourceUrl").and.returnValue(false);
|
|
161
|
+
|
|
162
|
+
expect(() => {
|
|
163
|
+
$templateRequest("tpl.html"); // should go through $sce
|
|
164
|
+
$rootScope.$digest();
|
|
165
|
+
}).toThrow();
|
|
166
|
+
|
|
167
|
+
$templateCache.put("tpl.html"); // is a no-op, so $sce check as well.
|
|
168
|
+
expect(() => {
|
|
169
|
+
$templateRequest("tpl.html");
|
|
170
|
+
$rootScope.$digest();
|
|
171
|
+
}).toThrow();
|
|
172
|
+
$templateCache.removeAll();
|
|
173
|
+
|
|
174
|
+
$templateCache.put("tpl.html", null); // makes no sense, but it's been added, so trust it.
|
|
175
|
+
expect(() => {
|
|
176
|
+
$templateRequest("tpl.html");
|
|
177
|
+
$rootScope.$digest();
|
|
178
|
+
}).not.toThrow();
|
|
179
|
+
$templateCache.removeAll();
|
|
180
|
+
|
|
181
|
+
$templateCache.put("tpl.html", ""); // should work (empty template)
|
|
182
|
+
expect(() => {
|
|
183
|
+
$templateRequest("tpl.html");
|
|
184
|
+
$rootScope.$digest();
|
|
185
|
+
}).not.toThrow();
|
|
186
|
+
$templateCache.removeAll();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("should keep track of how many requests are going on", async () => {
|
|
190
|
+
let res = $templateRequest("/mock/div");
|
|
191
|
+
$templateRequest("/mock/div");
|
|
192
|
+
|
|
193
|
+
expect($templateRequest.totalPendingRequests).toBe(2);
|
|
194
|
+
|
|
195
|
+
$rootScope.$digest();
|
|
196
|
+
await res;
|
|
197
|
+
expect($templateRequest.totalPendingRequests).toBe(0);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("should not try to parse a response as JSON", async () => {
|
|
201
|
+
const spy = jasmine.createSpy("success");
|
|
202
|
+
await $templateRequest("/mock/jsoninterpolation").then(spy);
|
|
203
|
+
|
|
204
|
+
expect(spy).toHaveBeenCalledOnceWith('"{{expr}}"');
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("should use custom response transformers (array)", async () => {
|
|
208
|
+
module.config(($httpProvider) => {
|
|
209
|
+
$httpProvider.defaults.transformResponse.push((data) => `${data}!!`);
|
|
210
|
+
});
|
|
211
|
+
let injector = createInjector(["test"]);
|
|
212
|
+
$rootScope = injector.get("$rootScope");
|
|
213
|
+
$templateRequest = injector.get("$templateRequest");
|
|
214
|
+
$templateCache = injector.get("$templateCache");
|
|
215
|
+
|
|
216
|
+
const spy = jasmine.createSpy("success");
|
|
217
|
+
|
|
218
|
+
await $templateRequest("/mock/jsoninterpolation").then(spy);
|
|
219
|
+
expect(spy).toHaveBeenCalledOnceWith('"{{expr}}"!!');
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("should use custom response transformers (function)", async () => {
|
|
223
|
+
module.config(($httpProvider) => {
|
|
224
|
+
$httpProvider.defaults.transformResponse = function (data) {
|
|
225
|
+
return `${data}!!`;
|
|
226
|
+
};
|
|
227
|
+
});
|
|
228
|
+
let injector = createInjector(["test"]);
|
|
229
|
+
$rootScope = injector.get("$rootScope");
|
|
230
|
+
$templateRequest = injector.get("$templateRequest");
|
|
231
|
+
$templateCache = injector.get("$templateCache");
|
|
232
|
+
const spy = jasmine.createSpy("success");
|
|
233
|
+
await $templateRequest("/mock/jsoninterpolation").then(spy);
|
|
234
|
+
expect(spy).toHaveBeenCalledOnceWith('"{{expr}}"!!');
|
|
235
|
+
});
|
|
236
|
+
});
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { publishExternalAPI } from "../../src/public";
|
|
2
|
+
import { createInjector } from "../../src/injector";
|
|
3
|
+
import { wait } from "../test-utils";
|
|
4
|
+
|
|
5
|
+
describe("$timeout", () => {
|
|
6
|
+
let injector;
|
|
7
|
+
let $interval;
|
|
8
|
+
let $rootScope;
|
|
9
|
+
let errors;
|
|
10
|
+
let $timeout;
|
|
11
|
+
let $browser;
|
|
12
|
+
let log;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
errors = [];
|
|
16
|
+
log = [];
|
|
17
|
+
publishExternalAPI().decorator("$exceptionHandler", function () {
|
|
18
|
+
return (exception) => {
|
|
19
|
+
errors.push(exception);
|
|
20
|
+
};
|
|
21
|
+
});
|
|
22
|
+
injector = createInjector(["ng"]);
|
|
23
|
+
|
|
24
|
+
$interval = injector.get("$interval");
|
|
25
|
+
$rootScope = injector.get("$rootScope");
|
|
26
|
+
$timeout = injector.get("$timeout");
|
|
27
|
+
$browser = injector.get("$browser");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should delegate functions to $browser.defer", (done) => {
|
|
31
|
+
let counter = 0;
|
|
32
|
+
$timeout(() => {
|
|
33
|
+
counter++;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
expect(counter).toBe(0);
|
|
37
|
+
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
expect(counter).toBe(1);
|
|
40
|
+
done();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("should call $apply after each callback is executed", (done) => {
|
|
45
|
+
const applySpy = spyOn($rootScope, "$apply").and.callThrough();
|
|
46
|
+
|
|
47
|
+
$timeout(() => {});
|
|
48
|
+
expect(applySpy).not.toHaveBeenCalled();
|
|
49
|
+
|
|
50
|
+
setTimeout(() => {
|
|
51
|
+
expect(applySpy).toHaveBeenCalled();
|
|
52
|
+
applySpy.calls.reset();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
$timeout(() => {});
|
|
56
|
+
$timeout(() => {});
|
|
57
|
+
setTimeout(() => {
|
|
58
|
+
expect(applySpy).toHaveBeenCalledTimes(2);
|
|
59
|
+
done();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("should NOT call $apply if skipApply is set to true", (done) => {
|
|
64
|
+
const applySpy = spyOn($rootScope, "$apply").and.callThrough();
|
|
65
|
+
|
|
66
|
+
$timeout(() => {}, 12, false);
|
|
67
|
+
expect(applySpy).not.toHaveBeenCalled();
|
|
68
|
+
|
|
69
|
+
setTimeout(() => {
|
|
70
|
+
expect(applySpy).not.toHaveBeenCalled();
|
|
71
|
+
done();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("should NOT call $evalAsync or $digest if invokeApply is set to false", (done) => {
|
|
76
|
+
const evalAsyncSpy = spyOn($rootScope, "$evalAsync").and.callThrough();
|
|
77
|
+
const digestSpy = spyOn($rootScope, "$digest").and.callThrough();
|
|
78
|
+
const fulfilledSpy = jasmine.createSpy("fulfilled");
|
|
79
|
+
|
|
80
|
+
$timeout(fulfilledSpy, 1, false);
|
|
81
|
+
|
|
82
|
+
setTimeout(() => {
|
|
83
|
+
expect(fulfilledSpy).toHaveBeenCalled();
|
|
84
|
+
expect(evalAsyncSpy).not.toHaveBeenCalled();
|
|
85
|
+
expect(digestSpy).not.toHaveBeenCalled();
|
|
86
|
+
done();
|
|
87
|
+
}, 1);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("should allow you to specify the delay time", () => {
|
|
91
|
+
const defer = spyOn($browser, "defer");
|
|
92
|
+
$timeout(() => {}, 123);
|
|
93
|
+
expect(defer).toHaveBeenCalledTimes(1);
|
|
94
|
+
expect(defer.calls.mostRecent().args[1]).toEqual(123);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("should return a promise which will be resolved with return value of the timeout callback", (done) => {
|
|
98
|
+
const promise = $timeout(() => {
|
|
99
|
+
log.push("timeout");
|
|
100
|
+
return "buba";
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
promise.then(
|
|
104
|
+
(value) => {
|
|
105
|
+
log.push(`promise success: ${value}`);
|
|
106
|
+
},
|
|
107
|
+
() => log.push("promise error"),
|
|
108
|
+
);
|
|
109
|
+
expect(log).toEqual([]);
|
|
110
|
+
|
|
111
|
+
setTimeout(() => {
|
|
112
|
+
expect(log).toEqual(["timeout", "promise success: buba"]);
|
|
113
|
+
done();
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("should allow the `fn` parameter to be optional", (done) => {
|
|
118
|
+
$timeout().then(
|
|
119
|
+
(value) => {
|
|
120
|
+
log.push(`promise success: ${value}`);
|
|
121
|
+
},
|
|
122
|
+
() => log.push("promise error"),
|
|
123
|
+
);
|
|
124
|
+
expect(log).toEqual([]);
|
|
125
|
+
|
|
126
|
+
setTimeout(() => {
|
|
127
|
+
expect(log).toEqual(["promise success: undefined"]);
|
|
128
|
+
log = [];
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
$timeout(1).then(
|
|
132
|
+
(value) => {
|
|
133
|
+
log.push(`promise success: ${value}`);
|
|
134
|
+
},
|
|
135
|
+
() => log.push("promise error"),
|
|
136
|
+
);
|
|
137
|
+
expect(log).toEqual([]);
|
|
138
|
+
setTimeout(() => {
|
|
139
|
+
expect(log).toEqual(["promise success: undefined"]);
|
|
140
|
+
done();
|
|
141
|
+
}, 1);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
describe("exception handling", () => {
|
|
145
|
+
it("should delegate exception to the $exceptionHandler service", async () => {
|
|
146
|
+
errors = [];
|
|
147
|
+
$timeout(() => {
|
|
148
|
+
errors = [];
|
|
149
|
+
throw "Test Error";
|
|
150
|
+
}, 1);
|
|
151
|
+
expect(errors).toEqual([]);
|
|
152
|
+
|
|
153
|
+
await wait(1);
|
|
154
|
+
expect(errors).toEqual([
|
|
155
|
+
"Test Error",
|
|
156
|
+
"Possibly unhandled rejection: Test Error",
|
|
157
|
+
]);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("should call $apply even if an exception is thrown in callback", async () => {
|
|
161
|
+
const applySpy = spyOn($rootScope, "$apply").and.callThrough();
|
|
162
|
+
|
|
163
|
+
$timeout(() => {
|
|
164
|
+
throw "Test $apply";
|
|
165
|
+
});
|
|
166
|
+
expect(applySpy).not.toHaveBeenCalled();
|
|
167
|
+
await wait(2);
|
|
168
|
+
expect(applySpy).toHaveBeenCalled();
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("should reject the timeout promise when an exception is thrown in the timeout callback", (done) => {
|
|
172
|
+
const promise = $timeout(() => {
|
|
173
|
+
throw "Some Error";
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
promise.then(
|
|
177
|
+
() => log.push("success"),
|
|
178
|
+
(reason) => {
|
|
179
|
+
log.push(`error: ${reason}`);
|
|
180
|
+
},
|
|
181
|
+
);
|
|
182
|
+
setTimeout(() => {
|
|
183
|
+
expect(log).toEqual(["error: Some Error"]);
|
|
184
|
+
done();
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("should pass the timeout arguments in the timeout callback even if an exception is thrown", (done) => {
|
|
189
|
+
const promise1 = $timeout(
|
|
190
|
+
(arg) => {
|
|
191
|
+
throw arg;
|
|
192
|
+
},
|
|
193
|
+
1,
|
|
194
|
+
true,
|
|
195
|
+
"Some Arguments",
|
|
196
|
+
);
|
|
197
|
+
const promise2 = $timeout(
|
|
198
|
+
(arg1, args2) => {
|
|
199
|
+
throw `${arg1} ${args2}`;
|
|
200
|
+
},
|
|
201
|
+
2,
|
|
202
|
+
false,
|
|
203
|
+
"Are Meant",
|
|
204
|
+
"To Be Thrown",
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
promise1.then(
|
|
208
|
+
() => log.push("success"),
|
|
209
|
+
(reason) => {
|
|
210
|
+
log.push(`error: ${reason}`);
|
|
211
|
+
},
|
|
212
|
+
);
|
|
213
|
+
promise2.then(
|
|
214
|
+
() => log.push("success"),
|
|
215
|
+
(reason) => {
|
|
216
|
+
log.push(`error: ${reason}`);
|
|
217
|
+
},
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
setTimeout(() => {
|
|
221
|
+
expect(log).toEqual([]);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
setTimeout(() => {
|
|
225
|
+
expect(log).toEqual(["error: Some Arguments"]);
|
|
226
|
+
}, 1);
|
|
227
|
+
setTimeout(() => {
|
|
228
|
+
expect(log).toEqual([
|
|
229
|
+
"error: Some Arguments",
|
|
230
|
+
"error: Are Meant To Be Thrown",
|
|
231
|
+
]);
|
|
232
|
+
done();
|
|
233
|
+
}, 15);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it("should forget references to relevant deferred even when exception is thrown", () => {
|
|
237
|
+
var promise = $timeout(
|
|
238
|
+
function () {
|
|
239
|
+
throw "Test Error";
|
|
240
|
+
},
|
|
241
|
+
0,
|
|
242
|
+
false,
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
const res = $timeout.cancel(promise);
|
|
246
|
+
expect(res).toBe(true);
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
describe("cancel", () => {
|
|
251
|
+
it("should cancel tasks", (done) => {
|
|
252
|
+
const task1 = jasmine.createSpy("task1");
|
|
253
|
+
const task2 = jasmine.createSpy("task2");
|
|
254
|
+
const task3 = jasmine.createSpy("task3");
|
|
255
|
+
const task4 = jasmine.createSpy("task4");
|
|
256
|
+
let promise1;
|
|
257
|
+
let promise3;
|
|
258
|
+
let promise4;
|
|
259
|
+
|
|
260
|
+
promise1 = $timeout(task1);
|
|
261
|
+
$timeout(task2);
|
|
262
|
+
promise3 = $timeout(task3, 333);
|
|
263
|
+
promise4 = $timeout(333);
|
|
264
|
+
promise3.then(task4, () => {});
|
|
265
|
+
|
|
266
|
+
$timeout.cancel(promise1);
|
|
267
|
+
$timeout.cancel(promise3);
|
|
268
|
+
$timeout.cancel(promise4);
|
|
269
|
+
setTimeout(() => {
|
|
270
|
+
expect(task1).not.toHaveBeenCalled();
|
|
271
|
+
expect(task2).toHaveBeenCalled();
|
|
272
|
+
expect(task3).not.toHaveBeenCalled();
|
|
273
|
+
expect(task4).not.toHaveBeenCalled();
|
|
274
|
+
done();
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it("should cancel the promise", (done) => {
|
|
279
|
+
const promise = $timeout(() => {});
|
|
280
|
+
promise.then(
|
|
281
|
+
(value) => {
|
|
282
|
+
log.push(`promise success: ${value}`);
|
|
283
|
+
},
|
|
284
|
+
(err) => {
|
|
285
|
+
log.push(`promise error: ${err}`);
|
|
286
|
+
},
|
|
287
|
+
(note) => {
|
|
288
|
+
log.push(`promise update: ${note}`);
|
|
289
|
+
},
|
|
290
|
+
);
|
|
291
|
+
expect(log).toEqual([]);
|
|
292
|
+
|
|
293
|
+
$timeout.cancel(promise);
|
|
294
|
+
setTimeout(() => {
|
|
295
|
+
expect(log).toEqual(["promise error: canceled"]);
|
|
296
|
+
done();
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it("should return true if a task was successfully canceled", (done) => {
|
|
301
|
+
const task1 = jasmine.createSpy("task1");
|
|
302
|
+
const task2 = jasmine.createSpy("task2");
|
|
303
|
+
let promise1;
|
|
304
|
+
let promise2;
|
|
305
|
+
|
|
306
|
+
promise1 = $timeout(task1);
|
|
307
|
+
setTimeout(() => {
|
|
308
|
+
promise2 = $timeout(task2);
|
|
309
|
+
|
|
310
|
+
expect($timeout.cancel(promise1)).toBe(false);
|
|
311
|
+
expect($timeout.cancel(promise2)).toBe(true);
|
|
312
|
+
done();
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it("should not throw an error when given an undefined promise", () => {
|
|
317
|
+
expect($timeout.cancel()).toBe(false);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it("should throw an error when given a non-$timeout promise", () => {
|
|
321
|
+
const promise = $timeout(() => {}).then(() => {});
|
|
322
|
+
expect(() => {
|
|
323
|
+
$timeout.cancel(promise);
|
|
324
|
+
}).toThrowError(/badprom/);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it("should forget references to relevant deferred", () => {
|
|
328
|
+
// $browser.defer.cancel is only called on cancel if the deferred object is still referenced
|
|
329
|
+
const cancelSpy = spyOn($browser.defer, "cancel").and.callThrough();
|
|
330
|
+
|
|
331
|
+
const promise = $timeout(() => {}, 0, false);
|
|
332
|
+
|
|
333
|
+
expect(cancelSpy).not.toHaveBeenCalled();
|
|
334
|
+
$timeout.cancel(promise);
|
|
335
|
+
expect(cancelSpy).toHaveBeenCalled();
|
|
336
|
+
|
|
337
|
+
// Promise deferred object should already be removed from the list and not cancellable again
|
|
338
|
+
$timeout.cancel(promise);
|
|
339
|
+
expect(cancelSpy).toHaveBeenCalled();
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
it("should not trigger digest when cancelled", () => {
|
|
343
|
+
const watchSpy = jasmine.createSpy("watchSpy");
|
|
344
|
+
$rootScope.$watch(watchSpy);
|
|
345
|
+
|
|
346
|
+
const t = $timeout();
|
|
347
|
+
$timeout.cancel(t);
|
|
348
|
+
expect(watchSpy).not.toHaveBeenCalled();
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
});
|