@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,343 @@
|
|
|
1
|
+
import { publishExternalAPI } from "../../src/public";
|
|
2
|
+
import { createInjector } from "../../src/injector";
|
|
3
|
+
import { wait } from "../test-utils";
|
|
4
|
+
|
|
5
|
+
describe("$interval", () => {
|
|
6
|
+
let injector;
|
|
7
|
+
let $interval;
|
|
8
|
+
let $rootScope;
|
|
9
|
+
let errors;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
errors = [];
|
|
13
|
+
publishExternalAPI().decorator("$exceptionHandler", () => {
|
|
14
|
+
return (exception) => {
|
|
15
|
+
errors.push(exception);
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
injector = createInjector(["ng"]);
|
|
19
|
+
|
|
20
|
+
$interval = injector.get("$interval");
|
|
21
|
+
$rootScope = injector.get("$rootScope");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("should run tasks repeatedly", async () => {
|
|
25
|
+
let counter = 0;
|
|
26
|
+
$interval(() => {
|
|
27
|
+
counter++;
|
|
28
|
+
}, 1);
|
|
29
|
+
expect(counter).toBe(0);
|
|
30
|
+
await wait(15);
|
|
31
|
+
expect(counter).toBeGreaterThanOrEqual(1);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("should call $apply after each task is executed", (done) => {
|
|
35
|
+
const applySpy = spyOn($rootScope, "$apply").and.callThrough();
|
|
36
|
+
|
|
37
|
+
$interval(() => {}, 1);
|
|
38
|
+
expect(applySpy).not.toHaveBeenCalled();
|
|
39
|
+
|
|
40
|
+
setTimeout(() => {
|
|
41
|
+
expect(applySpy).toHaveBeenCalled();
|
|
42
|
+
}, 3);
|
|
43
|
+
|
|
44
|
+
applySpy.calls.reset();
|
|
45
|
+
|
|
46
|
+
$interval(() => {}, 1);
|
|
47
|
+
$interval(() => {}, 1);
|
|
48
|
+
|
|
49
|
+
setTimeout(() => {
|
|
50
|
+
expect(applySpy).toHaveBeenCalledTimes(3);
|
|
51
|
+
done();
|
|
52
|
+
}, 1);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("should NOT call $apply if invokeApply is set to false", (done) => {
|
|
56
|
+
const applySpy = spyOn($rootScope, "$apply").and.callThrough();
|
|
57
|
+
|
|
58
|
+
$interval(() => {}, 1, 0, false);
|
|
59
|
+
expect(applySpy).not.toHaveBeenCalled();
|
|
60
|
+
|
|
61
|
+
setTimeout(() => {
|
|
62
|
+
expect(applySpy).not.toHaveBeenCalled();
|
|
63
|
+
done();
|
|
64
|
+
}, 2);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it("should NOT call $evalAsync or $digest if invokeApply is set to false", async () => {
|
|
68
|
+
const evalAsyncSpy = spyOn($rootScope, "$evalAsync").and.callThrough();
|
|
69
|
+
const digestSpy = spyOn($rootScope, "$digest").and.callThrough();
|
|
70
|
+
const notifySpy = jasmine.createSpy("notify");
|
|
71
|
+
|
|
72
|
+
$interval(notifySpy, 1, 1, false);
|
|
73
|
+
|
|
74
|
+
await wait(10);
|
|
75
|
+
expect(notifySpy).toHaveBeenCalled();
|
|
76
|
+
expect(evalAsyncSpy).not.toHaveBeenCalled();
|
|
77
|
+
expect(digestSpy).not.toHaveBeenCalled();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("should allow you to specify a number of iterations", async () => {
|
|
81
|
+
let counter = 0;
|
|
82
|
+
$interval(
|
|
83
|
+
() => {
|
|
84
|
+
counter++;
|
|
85
|
+
},
|
|
86
|
+
1,
|
|
87
|
+
2,
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
await wait(15);
|
|
91
|
+
expect(counter).toBe(2);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("should allow you to specify a number of arguments", (done) => {
|
|
95
|
+
const task1 = jasmine.createSpy("task1");
|
|
96
|
+
const task2 = jasmine.createSpy("task2");
|
|
97
|
+
const task3 = jasmine.createSpy("task3");
|
|
98
|
+
$interval(task1, 1, 2, true, "Task1");
|
|
99
|
+
$interval(task2, 1, 2, true, "Task2");
|
|
100
|
+
$interval(task3, 1, 2, true, "I", "am", "a", "Task3", "spy");
|
|
101
|
+
|
|
102
|
+
setTimeout(() => {
|
|
103
|
+
expect(task1).toHaveBeenCalledWith("Task1");
|
|
104
|
+
expect(task2).toHaveBeenCalledWith("Task2");
|
|
105
|
+
expect(task3).toHaveBeenCalledWith("I", "am", "a", "Task3", "spy");
|
|
106
|
+
}, 1);
|
|
107
|
+
|
|
108
|
+
task1.calls.reset();
|
|
109
|
+
task2.calls.reset();
|
|
110
|
+
task3.calls.reset();
|
|
111
|
+
|
|
112
|
+
setTimeout(() => {
|
|
113
|
+
expect(task1).toHaveBeenCalledWith("Task1");
|
|
114
|
+
expect(task2).toHaveBeenCalledWith("Task2");
|
|
115
|
+
expect(task3).toHaveBeenCalledWith("I", "am", "a", "Task3", "spy");
|
|
116
|
+
done();
|
|
117
|
+
}, 1);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("should return a promise which will be updated with the count on each iteration", async () => {
|
|
121
|
+
const log = [];
|
|
122
|
+
const promise = $interval(() => {
|
|
123
|
+
log.push("tick");
|
|
124
|
+
}, 1);
|
|
125
|
+
|
|
126
|
+
promise.then(
|
|
127
|
+
(value) => {
|
|
128
|
+
log.push(`promise success: ${value}`);
|
|
129
|
+
},
|
|
130
|
+
(err) => {
|
|
131
|
+
log.push(`promise error: ${err}`);
|
|
132
|
+
},
|
|
133
|
+
(note) => {
|
|
134
|
+
log.push(`promise update: ${note}`);
|
|
135
|
+
},
|
|
136
|
+
);
|
|
137
|
+
expect(log).toEqual([]);
|
|
138
|
+
|
|
139
|
+
await wait(5);
|
|
140
|
+
expect(log[0]).toEqual("tick");
|
|
141
|
+
expect(log[1]).toEqual("promise update: 0");
|
|
142
|
+
expect(log[2]).toEqual("tick");
|
|
143
|
+
expect(log[3]).toEqual("promise update: 1");
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("should return a promise which will be resolved after the specified number of iterations", async () => {
|
|
147
|
+
const log = [];
|
|
148
|
+
const promise = $interval(
|
|
149
|
+
() => {
|
|
150
|
+
log.push("tick");
|
|
151
|
+
},
|
|
152
|
+
1,
|
|
153
|
+
2,
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
promise.then(
|
|
157
|
+
(value) => {
|
|
158
|
+
log.push(`promise success: ${value}`);
|
|
159
|
+
},
|
|
160
|
+
(err) => {
|
|
161
|
+
log.push(`promise error: ${err}`);
|
|
162
|
+
},
|
|
163
|
+
(note) => {
|
|
164
|
+
log.push(`promise update: ${note}`);
|
|
165
|
+
},
|
|
166
|
+
);
|
|
167
|
+
expect(log).toEqual([]);
|
|
168
|
+
await wait(15);
|
|
169
|
+
expect(log).toEqual([
|
|
170
|
+
"tick",
|
|
171
|
+
"promise update: 0",
|
|
172
|
+
"tick",
|
|
173
|
+
"promise update: 1",
|
|
174
|
+
"promise success: 2",
|
|
175
|
+
]);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
describe("exception handling", () => {
|
|
179
|
+
it("should delegate exception to the $exceptionHandler service", (done) => {
|
|
180
|
+
$interval(() => {
|
|
181
|
+
throw "Test Error";
|
|
182
|
+
}, 10);
|
|
183
|
+
expect(errors).toEqual([]);
|
|
184
|
+
|
|
185
|
+
setTimeout(() => {
|
|
186
|
+
expect(errors).toEqual(["Test Error"]);
|
|
187
|
+
}, 10);
|
|
188
|
+
|
|
189
|
+
setTimeout(() => {
|
|
190
|
+
expect(errors).toEqual(["Test Error", "Test Error"]);
|
|
191
|
+
done();
|
|
192
|
+
}, 20);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it("should call $apply even if an exception is thrown in callback", (done) => {
|
|
196
|
+
const applySpy = spyOn($rootScope, "$apply").and.callThrough();
|
|
197
|
+
|
|
198
|
+
$interval(() => {
|
|
199
|
+
throw "Test Error";
|
|
200
|
+
}, 10);
|
|
201
|
+
expect(applySpy).not.toHaveBeenCalled();
|
|
202
|
+
|
|
203
|
+
setTimeout(() => {
|
|
204
|
+
expect(applySpy).toHaveBeenCalled();
|
|
205
|
+
done();
|
|
206
|
+
}, 11);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("should still update the interval promise when an exception is thrown", (done) => {
|
|
210
|
+
const promise = $interval(() => {
|
|
211
|
+
errors = [];
|
|
212
|
+
throw "Some Error";
|
|
213
|
+
}, 102);
|
|
214
|
+
|
|
215
|
+
promise.then(
|
|
216
|
+
(value) => {
|
|
217
|
+
errors.push(`promise success: ${value}`);
|
|
218
|
+
},
|
|
219
|
+
(err) => {
|
|
220
|
+
errors.push(`promise error: ${err}`);
|
|
221
|
+
},
|
|
222
|
+
(note) => {
|
|
223
|
+
errors.push(`promise update: ${note}`);
|
|
224
|
+
},
|
|
225
|
+
);
|
|
226
|
+
setTimeout(() => {
|
|
227
|
+
expect(errors[1]).toEqual("promise update: 0");
|
|
228
|
+
done();
|
|
229
|
+
}, 102);
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
describe("cancel", () => {
|
|
234
|
+
it("should cancel tasks", (done) => {
|
|
235
|
+
const task1 = jasmine.createSpy("task1", 1);
|
|
236
|
+
const task2 = jasmine.createSpy("task2", 1);
|
|
237
|
+
const task3 = jasmine.createSpy("task3", 1);
|
|
238
|
+
let promise1;
|
|
239
|
+
let promise3;
|
|
240
|
+
|
|
241
|
+
promise1 = $interval(task1, 2);
|
|
242
|
+
$interval(task2, 1);
|
|
243
|
+
promise3 = $interval(task3, 3);
|
|
244
|
+
|
|
245
|
+
$interval.cancel(promise3);
|
|
246
|
+
$interval.cancel(promise1);
|
|
247
|
+
setTimeout(() => {
|
|
248
|
+
expect(task1).not.toHaveBeenCalled();
|
|
249
|
+
expect(task2).toHaveBeenCalled();
|
|
250
|
+
expect(task3).not.toHaveBeenCalled();
|
|
251
|
+
done();
|
|
252
|
+
}, 1);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it("should cancel the promise", (done) => {
|
|
256
|
+
const promise = $interval(() => {}, 1);
|
|
257
|
+
const log = [];
|
|
258
|
+
promise.then(
|
|
259
|
+
(value) => {
|
|
260
|
+
log.push(`promise success: ${value}`);
|
|
261
|
+
},
|
|
262
|
+
(err) => {
|
|
263
|
+
log.push(`promise error: ${err}`);
|
|
264
|
+
},
|
|
265
|
+
(note) => {
|
|
266
|
+
log.push(`promise update: ${note}`);
|
|
267
|
+
},
|
|
268
|
+
);
|
|
269
|
+
expect(log).toEqual([]);
|
|
270
|
+
|
|
271
|
+
setTimeout(() => {
|
|
272
|
+
$interval.cancel(promise);
|
|
273
|
+
}, 1);
|
|
274
|
+
|
|
275
|
+
setTimeout(() => {
|
|
276
|
+
$rootScope.$apply(); // For resolving the promise -
|
|
277
|
+
// necessary since q uses $rootScope.evalAsync.
|
|
278
|
+
|
|
279
|
+
expect(log).toEqual(["promise update: 0", "promise error: canceled"]);
|
|
280
|
+
done();
|
|
281
|
+
}, 2);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it("should return true if a task was successfully canceled", (done) => {
|
|
285
|
+
const task1 = jasmine.createSpy("task1");
|
|
286
|
+
const task2 = jasmine.createSpy("task2");
|
|
287
|
+
let promise1;
|
|
288
|
+
let promise2;
|
|
289
|
+
|
|
290
|
+
promise1 = $interval(task1, 1, 1);
|
|
291
|
+
setTimeout(() => {
|
|
292
|
+
promise2 = $interval(task2, 1, 1);
|
|
293
|
+
|
|
294
|
+
expect($interval.cancel(promise1)).toBe(false);
|
|
295
|
+
expect($interval.cancel(promise2)).toBe(true);
|
|
296
|
+
done();
|
|
297
|
+
}, 1);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it("should not throw an error when given an undefined promise", () => {
|
|
301
|
+
expect($interval.cancel()).toBe(false);
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it("should throw an error when given a non-$interval promise", () => {
|
|
305
|
+
const promise = $interval(() => {}).then(() => {});
|
|
306
|
+
expect(() => {
|
|
307
|
+
$interval.cancel(promise);
|
|
308
|
+
}).toThrowError(/badprom/);
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it("should not trigger digest when cancelled", () => {
|
|
312
|
+
const watchSpy = jasmine.createSpy("watchSpy");
|
|
313
|
+
$rootScope.$watch(watchSpy);
|
|
314
|
+
|
|
315
|
+
const t = $interval();
|
|
316
|
+
$interval.cancel(t);
|
|
317
|
+
expect(watchSpy).not.toHaveBeenCalled();
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
describe("$window delegation", () => {
|
|
322
|
+
it("should use $window.setInterval instead of the global function", () => {
|
|
323
|
+
const setIntervalSpy = spyOn(window, "setInterval");
|
|
324
|
+
|
|
325
|
+
$interval(() => {}, 1);
|
|
326
|
+
expect(setIntervalSpy).toHaveBeenCalled();
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it("should use $window.clearInterval instead of the global function", (done) => {
|
|
330
|
+
const clearIntervalSpy = spyOn(window, "clearInterval");
|
|
331
|
+
|
|
332
|
+
$interval(() => {}, 1, 1);
|
|
333
|
+
setTimeout(() => {
|
|
334
|
+
expect(clearIntervalSpy).toHaveBeenCalled();
|
|
335
|
+
|
|
336
|
+
clearIntervalSpy.calls.reset();
|
|
337
|
+
$interval.cancel($interval(() => {}, 1));
|
|
338
|
+
expect(clearIntervalSpy).toHaveBeenCalled();
|
|
339
|
+
done();
|
|
340
|
+
}, 1);
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
});
|