@angular-wave/angular.ts 0.0.39 → 0.0.40
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/Makefile +2 -0
- package/README.md +1 -1
- package/dist/angular-ts.esm.js +2 -2
- package/dist/angular-ts.umd.js +2 -1
- package/package.json +1 -1
- package/rollup.config.js +10 -5
- package/src/angular.spec.js +25 -26
- package/src/animations/animate-css-driver.js +3 -3
- package/src/animations/animate-queue.js +7 -7
- package/src/animations/animation.js +2 -2
- package/src/animations/shared.js +6 -6
- package/src/binding.spec.js +7 -7
- package/src/core/animate/animate.js +5 -5
- package/src/core/animate/animate.spec.js +31 -31
- package/src/core/cache/cache-factory.html +18 -0
- package/src/core/cache/{cache-factor.test.js → cache-factory.test.js} +1 -1
- package/src/core/compile/compile.js +31 -25
- package/src/core/compile/compile.md +2 -2
- package/src/core/cookie-reader.spec.js +2 -2
- package/src/core/core.html +22 -0
- package/src/core/core.test.js +12 -0
- package/src/core/document.spec.js +4 -4
- package/src/core/exception-handler.js +30 -23
- package/src/core/interpolate/interpolate.js +7 -0
- package/src/core/{cache/cache-factor.html → location/location.html} +1 -1
- package/src/core/location/location.js +2 -2
- package/src/core/location/location.spec.js +17 -17
- package/src/core/location/location.test.js +12 -0
- package/src/core/on.spec.js +3 -3
- package/src/core/parser/parse.html +18 -0
- package/src/core/parser/parse.spec.js +1 -1
- package/src/core/parser/parse.test.js +12 -0
- package/src/core/prop.spec.js +3 -4
- package/src/core/pubsub/pubsub.html +18 -0
- package/src/core/pubsub/pubsub.spec.js +1 -1
- package/src/core/pubsub/pubsub.test.js +12 -0
- package/src/core/q/q.html +18 -0
- package/src/core/q/q.js +33 -0
- package/src/core/q/q.test.js +0 -0
- package/src/core/root-element.spec.js +4 -4
- package/src/core/sanitize/sanitize-uri.spec.js +1 -1
- package/src/core/sanitize/sanitize-uri.test.js +12 -0
- package/src/core/sanitize/sanitize.html +21 -0
- package/src/core/sce/sce.html +18 -0
- package/src/core/sce/sce.spec.js +2 -1
- package/src/core/sce/sce.test.js +12 -0
- package/src/core/scope/scope.html +18 -0
- package/src/core/scope/scope.js +1 -1
- package/src/core/scope/scope.spec.js +1 -1
- package/src/core/scope/scope.test.js +12 -0
- package/src/core/task-tracker-factory.js +9 -11
- package/src/core/timeout/timeout.html +18 -0
- package/src/core/timeout/timeout.js +9 -0
- package/src/core/timeout/timeout.spec.js +2 -2
- package/src/core/timeout/timout.test.js +12 -0
- package/src/core/url-utils/url-utils.html +18 -0
- package/src/core/url-utils/url-utils.spec.js +4 -2
- package/src/core/url-utils/url-utils.test.js +12 -0
- package/src/directive/attrs/attrs.spec.js +1 -2
- package/src/directive/attrs/boolean.spec.js +1 -2
- package/src/directive/attrs/element-style.spec.js +6 -7
- package/src/directive/attrs/src.spec.js +1 -2
- package/src/directive/bind/bind.spec.js +1 -2
- package/src/directive/class/class.spec.js +15 -16
- package/src/directive/cloak/cloak.spec.js +3 -4
- package/src/directive/controller/controller.spec.js +4 -5
- package/src/directive/events/click.spec.js +1 -2
- package/src/directive/events/event.spec.js +1 -1
- package/src/directive/events/events.js +7 -0
- package/src/directive/form/form.spec.js +17 -17
- package/src/directive/if/if.spec.js +2 -2
- package/src/directive/include/include.js +2 -2
- package/src/directive/include/include.spec.js +32 -32
- package/src/directive/init/init.spec.js +2 -3
- package/src/directive/input/input.spec.js +3 -3
- package/src/directive/list/list.spec.js +1 -2
- package/src/directive/model/model.js +13 -0
- package/src/directive/model/model.spec.js +4 -5
- package/src/directive/model-options/model-options.spec.js +3 -3
- package/src/directive/non-bindable/non-bindable.spec.js +1 -2
- package/src/directive/options/options.js +5 -5
- package/src/directive/options/options.spec.js +13 -13
- package/src/directive/ref/href.spec.js +1 -2
- package/src/directive/repeat/repeat.spec.js +12 -12
- package/src/directive/script/script.spec.js +2 -3
- package/src/directive/select/select.js +6 -6
- package/src/directive/select/select.spec.js +5 -5
- package/src/directive/show-hide/show-hide.spec.js +12 -13
- package/src/directive/style/style.spec.js +3 -4
- package/src/directive/switch/switch.spec.js +2 -3
- package/src/directive/validators/validators.spec.js +1 -1
- package/src/exts/aria/aria.spec.js +1 -2
- package/src/exts/messages/messages.spec.js +5 -5
- package/src/filters/filter.spec.js +5 -5
- package/src/filters/filters.html +21 -0
- package/src/filters/filters.spec.js +3 -3
- package/src/filters/filters.test.js +12 -0
- package/src/filters/limit-to.md +1 -1
- package/src/filters/limit-to.spec.js +4 -4
- package/src/filters/order-by.spec.js +2 -2
- package/src/index.js +186 -31
- package/src/loader.js +49 -11
- package/src/public.js +2 -3
- package/src/router/directives/state-directives.spec.js +90 -90
- package/src/router/directives/view-directive.js +2 -2
- package/src/router/directives/view-directive.spec.js +9 -9
- package/src/router/state/state.spec.js +2 -4
- package/src/router/template-factory.spec.js +2 -2
- package/src/router/transition/hook-registry.js +2 -2
- package/src/router/view/view.spec.js +1 -1
- package/src/services/browser.js +56 -39
- package/src/services/document.js +16 -13
- package/src/services/log.js +39 -43
- package/src/services/template-request.js +9 -0
- package/src/shared/common.js +0 -3
- package/src/shared/jqlite/jqlite.js +83 -89
- package/src/shared/jqlite/jqlite.spec.js +218 -222
- package/src/shared/strings.js +2 -2
- package/src/shared/test-utils.js +2 -2
- package/src/shared/utils.js +8 -11
- package/types/animations/shared.d.ts +1 -1
- package/types/core/exception-handler.d.ts +9 -42
- package/types/core/interpolate/interpolate.d.ts +1 -1
- package/types/core/q/q.d.ts +35 -1
- package/types/core/task-tracker-factory.d.ts +18 -11
- package/types/core/timeout/timeout.d.ts +10 -1
- package/types/directive/model/model.d.ts +28 -4
- package/types/index.d.ts +664 -79
- package/types/services/browser.d.ts +50 -20
- package/types/services/document.d.ts +13 -9
- package/types/services/log.d.ts +37 -34
- package/types/services/template-request.d.ts +1 -1
- package/types/shared/common.d.ts +0 -1
- package/types/shared/jqlite/jqlite.d.ts +6 -7
- package/types/shared/utils.d.ts +22 -22
- package/types-back/index.d.ts +1 -75
- /package/src/core/cache/{cache-factor.spec.js → cache-factory.spec.js} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JQLite, dealoc, kebabToCamel } from "./jqlite";
|
|
2
2
|
import { angularInit } from "../../loader";
|
|
3
3
|
import { createInjector } from "../../injector";
|
|
4
4
|
import { publishExternalAPI } from "../../public";
|
|
@@ -14,9 +14,9 @@ describe("jqLite", () => {
|
|
|
14
14
|
let injector;
|
|
15
15
|
|
|
16
16
|
beforeEach(() => {
|
|
17
|
-
a =
|
|
18
|
-
b =
|
|
19
|
-
c =
|
|
17
|
+
a = JQLite("<div>A</div>")[0];
|
|
18
|
+
b = JQLite("<div>B</div>")[0];
|
|
19
|
+
c = JQLite("<div>C</div>")[0];
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
beforeEach(() => {
|
|
@@ -35,8 +35,8 @@ describe("jqLite", () => {
|
|
|
35
35
|
let value =
|
|
36
36
|
_actual_ && expected && _actual_.length === expected.length;
|
|
37
37
|
for (let i = 0; value && i < expected.length; i++) {
|
|
38
|
-
const actual =
|
|
39
|
-
const expect =
|
|
38
|
+
const actual = JQLite(_actual_[i])[0];
|
|
39
|
+
const expect = JQLite(expected[i])[0];
|
|
40
40
|
value = value && equals(expect, actual);
|
|
41
41
|
msg = `Not equal at index: ${i} - Expected: ${expect} - Actual: ${actual}`;
|
|
42
42
|
}
|
|
@@ -53,20 +53,16 @@ describe("jqLite", () => {
|
|
|
53
53
|
dealoc(c);
|
|
54
54
|
});
|
|
55
55
|
|
|
56
|
-
it("should be jqLite by default", () => {
|
|
57
|
-
expect(jqLite).toBe(JQLite);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
56
|
describe("construction", () => {
|
|
61
57
|
it("should allow construction with text node", () => {
|
|
62
58
|
const text = a.firstChild;
|
|
63
|
-
const selected =
|
|
59
|
+
const selected = JQLite(text);
|
|
64
60
|
expect(selected.length).toEqual(1);
|
|
65
61
|
expect(selected[0]).toEqual(text);
|
|
66
62
|
});
|
|
67
63
|
|
|
68
64
|
it("should allow construction with html", () => {
|
|
69
|
-
const nodes =
|
|
65
|
+
const nodes = JQLite("<div>1</div><span>2</span>");
|
|
70
66
|
expect(nodes[0].parentNode).toBeDefined();
|
|
71
67
|
expect(nodes[0].parentNode.nodeType).toBe(11); /** Document Fragment * */
|
|
72
68
|
expect(nodes[0].parentNode).toBe(nodes[1].parentNode);
|
|
@@ -76,7 +72,7 @@ describe("jqLite", () => {
|
|
|
76
72
|
});
|
|
77
73
|
|
|
78
74
|
it("should allow construction of html with leading whitespace", () => {
|
|
79
|
-
const nodes =
|
|
75
|
+
const nodes = JQLite(" \n\r \r\n<div>1</div><span>2</span>");
|
|
80
76
|
expect(nodes[0].parentNode).toBeDefined();
|
|
81
77
|
expect(nodes[0].parentNode.nodeType).toBe(11); /** Document Fragment * */
|
|
82
78
|
expect(nodes[0].parentNode).toBe(nodes[1].parentNode);
|
|
@@ -95,7 +91,7 @@ describe("jqLite", () => {
|
|
|
95
91
|
|
|
96
92
|
nodeNames.forEach((nodeName) => {
|
|
97
93
|
customNodeName = `${nodeName}-foo`;
|
|
98
|
-
nodes =
|
|
94
|
+
nodes = JQLite(`<${customNodeName}>Hello, world !</${customNodeName}>`);
|
|
99
95
|
|
|
100
96
|
expect(nodes.length).toBe(1);
|
|
101
97
|
expect(nodes[0].nodeName.toLowerCase()).toBe(customNodeName);
|
|
@@ -108,31 +104,31 @@ describe("jqLite", () => {
|
|
|
108
104
|
});
|
|
109
105
|
|
|
110
106
|
it("should allow creation of comment tags", () => {
|
|
111
|
-
const nodes =
|
|
107
|
+
const nodes = JQLite("<!-- foo -->");
|
|
112
108
|
expect(nodes.length).toBe(1);
|
|
113
109
|
expect(nodes[0].nodeType).toBe(8);
|
|
114
110
|
});
|
|
115
111
|
|
|
116
112
|
it("should allow creation of script tags", () => {
|
|
117
|
-
const nodes =
|
|
113
|
+
const nodes = JQLite("<script></script>");
|
|
118
114
|
expect(nodes.length).toBe(1);
|
|
119
115
|
expect(nodes[0].tagName.toUpperCase()).toBe("SCRIPT");
|
|
120
116
|
});
|
|
121
117
|
|
|
122
118
|
it("should wrap document fragment", () => {
|
|
123
|
-
const fragment =
|
|
119
|
+
const fragment = JQLite(window.document.createDocumentFragment());
|
|
124
120
|
expect(fragment.length).toBe(1);
|
|
125
121
|
expect(fragment[0].nodeType).toBe(11);
|
|
126
122
|
});
|
|
127
123
|
|
|
128
124
|
it("should allow construction of <option> elements", () => {
|
|
129
|
-
const nodes =
|
|
125
|
+
const nodes = JQLite("<option>");
|
|
130
126
|
expect(nodes.length).toBe(1);
|
|
131
127
|
expect(nodes[0].nodeName.toLowerCase()).toBe("option");
|
|
132
128
|
});
|
|
133
129
|
|
|
134
130
|
it("should allow construction of multiple <option> elements", () => {
|
|
135
|
-
const nodes =
|
|
131
|
+
const nodes = JQLite("<option></option><option></option>");
|
|
136
132
|
expect(nodes.length).toBe(2);
|
|
137
133
|
expect(nodes[0].nodeName.toLowerCase()).toBe("option");
|
|
138
134
|
expect(nodes[1].nodeName.toLowerCase()).toBe("option");
|
|
@@ -159,7 +155,7 @@ describe("jqLite", () => {
|
|
|
159
155
|
name,
|
|
160
156
|
),
|
|
161
157
|
() => {
|
|
162
|
-
const nodes =
|
|
158
|
+
const nodes = JQLite("<$NAME$>".replace("$NAME$", name));
|
|
163
159
|
expect(nodes.length).toBe(1);
|
|
164
160
|
expect(nodes[0].nodeName.toLowerCase()).toBe(name);
|
|
165
161
|
},
|
|
@@ -172,7 +168,7 @@ describe("jqLite", () => {
|
|
|
172
168
|
// This test case attempts to close the tags which wrap input
|
|
173
169
|
// based on matching done in wrapMap, escaping the wrapper & thus
|
|
174
170
|
// triggering an error when descending.
|
|
175
|
-
const el =
|
|
171
|
+
const el = JQLite("<td></td></tr></tbody></table><td></td>");
|
|
176
172
|
expect(el.length).toBe(2);
|
|
177
173
|
expect(el[0].nodeName.toLowerCase()).toBe("td");
|
|
178
174
|
expect(el[1].nodeName.toLowerCase()).toBe("td");
|
|
@@ -182,7 +178,7 @@ describe("jqLite", () => {
|
|
|
182
178
|
it("shouldn't unsanitize sanitized code", (done) => {
|
|
183
179
|
let counter = 0;
|
|
184
180
|
const assertCount = 13;
|
|
185
|
-
const container =
|
|
181
|
+
const container = JQLite("<div></div>");
|
|
186
182
|
|
|
187
183
|
function donePartial() {
|
|
188
184
|
counter++;
|
|
@@ -192,7 +188,7 @@ describe("jqLite", () => {
|
|
|
192
188
|
done();
|
|
193
189
|
}
|
|
194
190
|
}
|
|
195
|
-
|
|
191
|
+
JQLite(window.document.body).append(container);
|
|
196
192
|
window.xss = jasmine.createSpy("xss");
|
|
197
193
|
|
|
198
194
|
// Thanks to Masato Kinugawa from Cure53 for providing the following test cases.
|
|
@@ -214,10 +210,10 @@ describe("jqLite", () => {
|
|
|
214
210
|
|
|
215
211
|
"<option><style></option></select><img src=url404 onerror=xss(12)></style>",
|
|
216
212
|
].forEach((htmlString, index) => {
|
|
217
|
-
const element =
|
|
213
|
+
const element = JQLite("<div></div>");
|
|
218
214
|
|
|
219
215
|
container.append(element);
|
|
220
|
-
element.append(
|
|
216
|
+
element.append(JQLite(htmlString));
|
|
221
217
|
|
|
222
218
|
setTimeout(() => {
|
|
223
219
|
expect(window.xss).not.toHaveBeenCalledWith(index);
|
|
@@ -230,30 +226,30 @@ describe("jqLite", () => {
|
|
|
230
226
|
|
|
231
227
|
describe("inheritedData", () => {
|
|
232
228
|
it("should retrieve data attached to the current element", () => {
|
|
233
|
-
const element =
|
|
229
|
+
const element = JQLite("<i>foo</i>");
|
|
234
230
|
element.data("myData", "abc");
|
|
235
231
|
expect(element.inheritedData("myData")).toBe("abc");
|
|
236
232
|
dealoc(element);
|
|
237
233
|
});
|
|
238
234
|
|
|
239
235
|
it("should walk up the dom to find data", () => {
|
|
240
|
-
const element =
|
|
241
|
-
const deepChild =
|
|
236
|
+
const element = JQLite("<ul><li><p><b>deep deep</b><p></li></ul>");
|
|
237
|
+
const deepChild = JQLite(element[0].getElementsByTagName("b")[0]);
|
|
242
238
|
element.data("myData", "abc");
|
|
243
239
|
expect(deepChild.inheritedData("myData")).toBe("abc");
|
|
244
240
|
dealoc(element);
|
|
245
241
|
});
|
|
246
242
|
|
|
247
243
|
it("should return undefined when no data was found", () => {
|
|
248
|
-
const element =
|
|
249
|
-
const deepChild =
|
|
244
|
+
const element = JQLite("<ul><li><p><b>deep deep</b><p></li></ul>");
|
|
245
|
+
const deepChild = JQLite(element[0].getElementsByTagName("b")[0]);
|
|
250
246
|
expect(deepChild.inheritedData("myData")).toBeFalsy();
|
|
251
247
|
dealoc(element);
|
|
252
248
|
});
|
|
253
249
|
|
|
254
250
|
it("should work with the child html element instead if the current element is the document obj", () => {
|
|
255
251
|
const item = {};
|
|
256
|
-
const doc =
|
|
252
|
+
const doc = JQLite(window.document);
|
|
257
253
|
const html = doc.find("html");
|
|
258
254
|
|
|
259
255
|
html.data("item", item);
|
|
@@ -263,7 +259,7 @@ describe("jqLite", () => {
|
|
|
263
259
|
});
|
|
264
260
|
|
|
265
261
|
it("should return null values", () => {
|
|
266
|
-
const ul =
|
|
262
|
+
const ul = JQLite("<ul><li><p><b>deep deep</b><p></li></ul>");
|
|
267
263
|
const li = ul.find("li");
|
|
268
264
|
const b = li.find("b");
|
|
269
265
|
|
|
@@ -277,9 +273,9 @@ describe("jqLite", () => {
|
|
|
277
273
|
});
|
|
278
274
|
|
|
279
275
|
it("should pass through DocumentFragment boundaries via host", () => {
|
|
280
|
-
const host =
|
|
276
|
+
const host = JQLite("<div></div>");
|
|
281
277
|
const frag = window.document.createDocumentFragment();
|
|
282
|
-
const $frag =
|
|
278
|
+
const $frag = JQLite(frag);
|
|
283
279
|
frag.host = host[0];
|
|
284
280
|
host.data("foo", 123);
|
|
285
281
|
host.append($frag);
|
|
@@ -292,21 +288,21 @@ describe("jqLite", () => {
|
|
|
292
288
|
|
|
293
289
|
describe("scope", () => {
|
|
294
290
|
it("should retrieve scope attached to the current element", () => {
|
|
295
|
-
const element =
|
|
291
|
+
const element = JQLite("<i>foo</i>");
|
|
296
292
|
element.data("$scope", scope);
|
|
297
293
|
expect(element.scope()).toBe(scope);
|
|
298
294
|
dealoc(element);
|
|
299
295
|
});
|
|
300
296
|
|
|
301
297
|
it("should retrieve isolate scope attached to the current element", () => {
|
|
302
|
-
const element =
|
|
298
|
+
const element = JQLite("<i>foo</i>");
|
|
303
299
|
element.data("$isolateScope", scope);
|
|
304
300
|
expect(element.isolateScope()).toBe(scope);
|
|
305
301
|
dealoc(element);
|
|
306
302
|
});
|
|
307
303
|
|
|
308
304
|
it("should retrieve scope attached to the html element if it's requested on the document", () => {
|
|
309
|
-
const doc =
|
|
305
|
+
const doc = JQLite(window.document);
|
|
310
306
|
const html = doc.find("html");
|
|
311
307
|
const scope = {};
|
|
312
308
|
|
|
@@ -318,16 +314,16 @@ describe("jqLite", () => {
|
|
|
318
314
|
});
|
|
319
315
|
|
|
320
316
|
it("should walk up the dom to find scope", () => {
|
|
321
|
-
const element =
|
|
322
|
-
const deepChild =
|
|
317
|
+
const element = JQLite("<ul><li><p><b>deep deep</b><p></li></ul>");
|
|
318
|
+
const deepChild = JQLite(element[0].getElementsByTagName("b")[0]);
|
|
323
319
|
element.data("$scope", scope);
|
|
324
320
|
expect(deepChild.scope()).toBe(scope);
|
|
325
321
|
dealoc(element);
|
|
326
322
|
});
|
|
327
323
|
|
|
328
324
|
it("should return undefined when no scope was found", () => {
|
|
329
|
-
const element =
|
|
330
|
-
const deepChild =
|
|
325
|
+
const element = JQLite("<ul><li><p><b>deep deep</b><p></li></ul>");
|
|
326
|
+
const deepChild = JQLite(element[0].getElementsByTagName("b")[0]);
|
|
331
327
|
expect(deepChild.scope()).toBeFalsy();
|
|
332
328
|
dealoc(element);
|
|
333
329
|
});
|
|
@@ -335,22 +331,22 @@ describe("jqLite", () => {
|
|
|
335
331
|
|
|
336
332
|
describe("isolateScope", () => {
|
|
337
333
|
it("should retrieve isolate scope attached to the current element", () => {
|
|
338
|
-
const element =
|
|
334
|
+
const element = JQLite("<i>foo</i>");
|
|
339
335
|
element.data("$isolateScope", scope);
|
|
340
336
|
expect(element.isolateScope()).toBe(scope);
|
|
341
337
|
dealoc(element);
|
|
342
338
|
});
|
|
343
339
|
|
|
344
340
|
it("should not walk up the dom to find scope", () => {
|
|
345
|
-
const element =
|
|
346
|
-
const deepChild =
|
|
341
|
+
const element = JQLite("<ul><li><p><b>deep deep</b><p></li></ul>");
|
|
342
|
+
const deepChild = JQLite(element[0].getElementsByTagName("b")[0]);
|
|
347
343
|
element.data("$isolateScope", scope);
|
|
348
344
|
expect(deepChild.isolateScope()).toBeUndefined();
|
|
349
345
|
dealoc(element);
|
|
350
346
|
});
|
|
351
347
|
|
|
352
348
|
it("should return undefined when no scope was found", () => {
|
|
353
|
-
const element =
|
|
349
|
+
const element = JQLite("<div></div>");
|
|
354
350
|
expect(element.isolateScope()).toBeFalsy();
|
|
355
351
|
dealoc(element);
|
|
356
352
|
});
|
|
@@ -358,7 +354,7 @@ describe("jqLite", () => {
|
|
|
358
354
|
|
|
359
355
|
describe("injector", () => {
|
|
360
356
|
it("should retrieve injector attached to the current element or its parent", () => {
|
|
361
|
-
const template =
|
|
357
|
+
const template = JQLite("<div><span></span></div>");
|
|
362
358
|
const span = template.children().eq(0);
|
|
363
359
|
const injector = angularInit(template[0]);
|
|
364
360
|
|
|
@@ -367,7 +363,7 @@ describe("jqLite", () => {
|
|
|
367
363
|
});
|
|
368
364
|
|
|
369
365
|
it("should retrieve injector attached to the html element if it's requested on document", () => {
|
|
370
|
-
const doc =
|
|
366
|
+
const doc = JQLite(window.document);
|
|
371
367
|
const html = doc.find("html");
|
|
372
368
|
const injector = {};
|
|
373
369
|
|
|
@@ -379,7 +375,7 @@ describe("jqLite", () => {
|
|
|
379
375
|
});
|
|
380
376
|
|
|
381
377
|
it("should do nothing with a noncompiled template", () => {
|
|
382
|
-
const template =
|
|
378
|
+
const template = JQLite("<div><span></span></div>");
|
|
383
379
|
expect(template.injector()).toBeUndefined();
|
|
384
380
|
dealoc(template);
|
|
385
381
|
});
|
|
@@ -387,7 +383,7 @@ describe("jqLite", () => {
|
|
|
387
383
|
|
|
388
384
|
describe("controller", () => {
|
|
389
385
|
it("should retrieve controller attached to the current element or its parent", () => {
|
|
390
|
-
const div =
|
|
386
|
+
const div = JQLite("<div><span></span></div>");
|
|
391
387
|
const span = div.find("span");
|
|
392
388
|
|
|
393
389
|
div.data("$ngControllerController", "ngController");
|
|
@@ -407,29 +403,29 @@ describe("jqLite", () => {
|
|
|
407
403
|
|
|
408
404
|
describe("data", () => {
|
|
409
405
|
it("should set and get and remove data", () => {
|
|
410
|
-
const selected =
|
|
406
|
+
const selected = JQLite([a, b, c]);
|
|
411
407
|
|
|
412
408
|
expect(selected.data("prop")).toBeUndefined();
|
|
413
409
|
expect(selected.data("prop", "value")).toBe(selected);
|
|
414
410
|
expect(selected.data("prop")).toBe("value");
|
|
415
|
-
expect(
|
|
416
|
-
expect(
|
|
417
|
-
expect(
|
|
411
|
+
expect(JQLite(a).data("prop")).toBe("value");
|
|
412
|
+
expect(JQLite(b).data("prop")).toBe("value");
|
|
413
|
+
expect(JQLite(c).data("prop")).toBe("value");
|
|
418
414
|
|
|
419
|
-
|
|
420
|
-
expect(
|
|
415
|
+
JQLite(a).data("prop", "new value");
|
|
416
|
+
expect(JQLite(a).data("prop")).toBe("new value");
|
|
421
417
|
expect(selected.data("prop")).toBe("new value");
|
|
422
|
-
expect(
|
|
423
|
-
expect(
|
|
418
|
+
expect(JQLite(b).data("prop")).toBe("value");
|
|
419
|
+
expect(JQLite(c).data("prop")).toBe("value");
|
|
424
420
|
|
|
425
421
|
expect(selected.removeData("prop")).toBe(selected);
|
|
426
|
-
expect(
|
|
427
|
-
expect(
|
|
428
|
-
expect(
|
|
422
|
+
expect(JQLite(a).data("prop")).toBeUndefined();
|
|
423
|
+
expect(JQLite(b).data("prop")).toBeUndefined();
|
|
424
|
+
expect(JQLite(c).data("prop")).toBeUndefined();
|
|
429
425
|
});
|
|
430
426
|
|
|
431
427
|
it("should only remove the specified value when providing a property name to removeData", () => {
|
|
432
|
-
const selected =
|
|
428
|
+
const selected = JQLite(a);
|
|
433
429
|
|
|
434
430
|
expect(selected.data("prop1")).toBeUndefined();
|
|
435
431
|
|
|
@@ -449,7 +445,7 @@ describe("jqLite", () => {
|
|
|
449
445
|
|
|
450
446
|
it("should not remove event handlers on removeData()", () => {
|
|
451
447
|
let log = "";
|
|
452
|
-
const elm =
|
|
448
|
+
const elm = JQLite(a);
|
|
453
449
|
elm.on("click", () => {
|
|
454
450
|
log += "click;";
|
|
455
451
|
});
|
|
@@ -460,7 +456,7 @@ describe("jqLite", () => {
|
|
|
460
456
|
});
|
|
461
457
|
|
|
462
458
|
it("should allow to set data after removeData() with event handlers present", () => {
|
|
463
|
-
const elm =
|
|
459
|
+
const elm = JQLite(a);
|
|
464
460
|
elm.on("click", () => {});
|
|
465
461
|
elm.data("key1", "value1");
|
|
466
462
|
elm.removeData();
|
|
@@ -470,7 +466,7 @@ describe("jqLite", () => {
|
|
|
470
466
|
});
|
|
471
467
|
|
|
472
468
|
it("should allow to set data after removeData() without event handlers present", () => {
|
|
473
|
-
const elm =
|
|
469
|
+
const elm = JQLite(a);
|
|
474
470
|
elm.data("key1", "value1");
|
|
475
471
|
elm.removeData();
|
|
476
472
|
elm.data("key2", "value2");
|
|
@@ -479,64 +475,64 @@ describe("jqLite", () => {
|
|
|
479
475
|
});
|
|
480
476
|
|
|
481
477
|
it("should remove user data on cleanData()", () => {
|
|
482
|
-
const selected =
|
|
478
|
+
const selected = JQLite([a, b, c]);
|
|
483
479
|
|
|
484
480
|
selected.data("prop", "value");
|
|
485
|
-
|
|
481
|
+
JQLite(b).data("prop", "new value");
|
|
486
482
|
|
|
487
|
-
|
|
483
|
+
JQLite.cleanData(selected);
|
|
488
484
|
|
|
489
|
-
expect(
|
|
490
|
-
expect(
|
|
491
|
-
expect(
|
|
485
|
+
expect(JQLite(a).data("prop")).toBeUndefined();
|
|
486
|
+
expect(JQLite(b).data("prop")).toBeUndefined();
|
|
487
|
+
expect(JQLite(c).data("prop")).toBeUndefined();
|
|
492
488
|
});
|
|
493
489
|
|
|
494
490
|
it("should remove event handlers on cleanData()", () => {
|
|
495
|
-
const selected =
|
|
491
|
+
const selected = JQLite([a, b, c]);
|
|
496
492
|
|
|
497
493
|
let log = "";
|
|
498
|
-
const elm =
|
|
494
|
+
const elm = JQLite(b);
|
|
499
495
|
elm.on("click", () => {
|
|
500
496
|
log += "click;";
|
|
501
497
|
});
|
|
502
|
-
|
|
498
|
+
JQLite.cleanData(selected);
|
|
503
499
|
|
|
504
500
|
browserTrigger(b, "click");
|
|
505
501
|
expect(log).toBe("");
|
|
506
502
|
});
|
|
507
503
|
|
|
508
504
|
it("should remove user data & event handlers on cleanData()", () => {
|
|
509
|
-
const selected =
|
|
505
|
+
const selected = JQLite([a, b, c]);
|
|
510
506
|
|
|
511
507
|
let log = "";
|
|
512
|
-
const elm =
|
|
508
|
+
const elm = JQLite(b);
|
|
513
509
|
elm.on("click", () => {
|
|
514
510
|
log += "click;";
|
|
515
511
|
});
|
|
516
512
|
|
|
517
513
|
selected.data("prop", "value");
|
|
518
|
-
|
|
514
|
+
JQLite(a).data("prop", "new value");
|
|
519
515
|
|
|
520
|
-
|
|
516
|
+
JQLite.cleanData(selected);
|
|
521
517
|
|
|
522
518
|
browserTrigger(b, "click");
|
|
523
519
|
expect(log).toBe("");
|
|
524
520
|
|
|
525
|
-
expect(
|
|
526
|
-
expect(
|
|
527
|
-
expect(
|
|
521
|
+
expect(JQLite(a).data("prop")).toBeUndefined();
|
|
522
|
+
expect(JQLite(b).data("prop")).toBeUndefined();
|
|
523
|
+
expect(JQLite(c).data("prop")).toBeUndefined();
|
|
528
524
|
});
|
|
529
525
|
|
|
530
526
|
it("should not break on cleanData(), if element has no data", () => {
|
|
531
|
-
const selected =
|
|
527
|
+
const selected = JQLite([a, b, c]);
|
|
532
528
|
spyOn(CACHE, "get").and.returnValue(undefined);
|
|
533
529
|
expect(() => {
|
|
534
|
-
|
|
530
|
+
JQLite.cleanData(selected);
|
|
535
531
|
}).not.toThrow();
|
|
536
532
|
});
|
|
537
533
|
|
|
538
534
|
it("should add and remove data on SVGs", () => {
|
|
539
|
-
const svg =
|
|
535
|
+
const svg = JQLite("<svg><rect></rect></svg>");
|
|
540
536
|
|
|
541
537
|
svg.data("svg-level", 1);
|
|
542
538
|
expect(svg.data("svg-level")).toBe(1);
|
|
@@ -549,7 +545,7 @@ describe("jqLite", () => {
|
|
|
549
545
|
|
|
550
546
|
it("should not add to the cache if the node is a comment or text node", () => {
|
|
551
547
|
const initial = CACHE.size;
|
|
552
|
-
const nodes =
|
|
548
|
+
const nodes = JQLite("<!-- some comment --> and some text");
|
|
553
549
|
expect(CACHE.size).toEqual(initial);
|
|
554
550
|
nodes.data("someKey");
|
|
555
551
|
expect(CACHE.size).toEqual(initial);
|
|
@@ -562,32 +558,32 @@ describe("jqLite", () => {
|
|
|
562
558
|
document.body.appendChild(node);
|
|
563
559
|
|
|
564
560
|
expect(CACHE.has(node[EXPANDO])).toBe(false);
|
|
565
|
-
expect(
|
|
561
|
+
expect(JQLite.data(node, "foo")).toBeUndefined();
|
|
566
562
|
expect(CACHE.has(node[EXPANDO])).toBe(false);
|
|
567
563
|
|
|
568
|
-
|
|
564
|
+
JQLite.data(node, "foo", "bar");
|
|
569
565
|
|
|
570
566
|
expect(CACHE.has(node[EXPANDO])).toBe(true);
|
|
571
|
-
expect(
|
|
572
|
-
expect(
|
|
567
|
+
expect(JQLite.data(node, "foo")).toBe("bar");
|
|
568
|
+
expect(JQLite(node).data("foo")).toBe("bar");
|
|
573
569
|
|
|
574
|
-
expect(
|
|
570
|
+
expect(JQLite.data(node)).toBe(JQLite(node).data());
|
|
575
571
|
|
|
576
|
-
|
|
577
|
-
expect(
|
|
572
|
+
JQLite.removeData(node, "foo");
|
|
573
|
+
expect(JQLite.data(node, "foo")).toBeUndefined();
|
|
578
574
|
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
expect(
|
|
575
|
+
JQLite.data(node, "bar", "baz");
|
|
576
|
+
JQLite.removeData(node);
|
|
577
|
+
JQLite.removeData(node);
|
|
578
|
+
expect(JQLite.data(node, "bar")).toBeUndefined();
|
|
583
579
|
|
|
584
|
-
|
|
580
|
+
JQLite(node).remove();
|
|
585
581
|
expect(CACHE.has(node[EXPANDO])).toBe(false);
|
|
586
582
|
});
|
|
587
583
|
|
|
588
584
|
it("should emit $destroy event if element removed via remove()", function () {
|
|
589
585
|
var log = "";
|
|
590
|
-
var element =
|
|
586
|
+
var element = JQLite(a);
|
|
591
587
|
element.on("$destroy", function () {
|
|
592
588
|
log += "destroy;";
|
|
593
589
|
});
|
|
@@ -597,7 +593,7 @@ describe("jqLite", () => {
|
|
|
597
593
|
|
|
598
594
|
it("should emit $destroy event if an element is removed via html('')", () => {
|
|
599
595
|
let log = [];
|
|
600
|
-
const element =
|
|
596
|
+
const element = JQLite("<div><span>x</span></div>");
|
|
601
597
|
element.find("span").on("$destroy", () => log.push("destroyed"));
|
|
602
598
|
element.html("");
|
|
603
599
|
expect(element.html()).toBe("");
|
|
@@ -606,7 +602,7 @@ describe("jqLite", () => {
|
|
|
606
602
|
|
|
607
603
|
it("should emit $destroy event if an element is removed via empty()", () => {
|
|
608
604
|
let log = [];
|
|
609
|
-
const element =
|
|
605
|
+
const element = JQLite("<div><span>x</span></div>");
|
|
610
606
|
element.find("span").on("$destroy", () => log.push("destroyed"));
|
|
611
607
|
|
|
612
608
|
element.empty();
|
|
@@ -616,7 +612,7 @@ describe("jqLite", () => {
|
|
|
616
612
|
});
|
|
617
613
|
|
|
618
614
|
it("should keep data if an element is removed via detach()", () => {
|
|
619
|
-
const root =
|
|
615
|
+
const root = JQLite("<div><span>abc</span></div>");
|
|
620
616
|
const span = root.find("span");
|
|
621
617
|
const data = span.data();
|
|
622
618
|
|
|
@@ -629,7 +625,7 @@ describe("jqLite", () => {
|
|
|
629
625
|
});
|
|
630
626
|
|
|
631
627
|
it("should retrieve all data if called without params", () => {
|
|
632
|
-
const element =
|
|
628
|
+
const element = JQLite(a);
|
|
633
629
|
expect(element.data()).toEqual({});
|
|
634
630
|
|
|
635
631
|
element.data("foo", "bar");
|
|
@@ -640,7 +636,7 @@ describe("jqLite", () => {
|
|
|
640
636
|
});
|
|
641
637
|
|
|
642
638
|
it("should create a new data object if called without args", () => {
|
|
643
|
-
const element =
|
|
639
|
+
const element = JQLite(a);
|
|
644
640
|
const data = element.data();
|
|
645
641
|
|
|
646
642
|
expect(data).toEqual({});
|
|
@@ -649,7 +645,7 @@ describe("jqLite", () => {
|
|
|
649
645
|
});
|
|
650
646
|
|
|
651
647
|
it("should create a new data object if called with a single object arg", () => {
|
|
652
|
-
const element =
|
|
648
|
+
const element = JQLite(a);
|
|
653
649
|
const newData = { foo: "bar" };
|
|
654
650
|
|
|
655
651
|
element.data(newData);
|
|
@@ -658,7 +654,7 @@ describe("jqLite", () => {
|
|
|
658
654
|
});
|
|
659
655
|
|
|
660
656
|
it("should merge existing data object with a new one if called with a single object arg", () => {
|
|
661
|
-
const element =
|
|
657
|
+
const element = JQLite(a);
|
|
662
658
|
element.data("existing", "val");
|
|
663
659
|
expect(element.data()).toEqual({ existing: "val" });
|
|
664
660
|
|
|
@@ -676,7 +672,7 @@ describe("jqLite", () => {
|
|
|
676
672
|
|
|
677
673
|
describe("data cleanup", () => {
|
|
678
674
|
it("should remove data on element removal", () => {
|
|
679
|
-
const div =
|
|
675
|
+
const div = JQLite("<div><span>text</span></div>");
|
|
680
676
|
const span = div.find("span");
|
|
681
677
|
|
|
682
678
|
span.data("name", "AngularJS");
|
|
@@ -685,7 +681,7 @@ describe("jqLite", () => {
|
|
|
685
681
|
});
|
|
686
682
|
|
|
687
683
|
it("should remove event listeners on element removal", () => {
|
|
688
|
-
const div =
|
|
684
|
+
const div = JQLite("<div><span>text</span></div>");
|
|
689
685
|
const span = div.find("span");
|
|
690
686
|
let log = "";
|
|
691
687
|
|
|
@@ -702,7 +698,7 @@ describe("jqLite", () => {
|
|
|
702
698
|
});
|
|
703
699
|
|
|
704
700
|
it("should work if the descendants of the element change while it's being removed", () => {
|
|
705
|
-
const div =
|
|
701
|
+
const div = JQLite("<div><p><span>text</span></p></div>");
|
|
706
702
|
div.find("p").on("$destroy", () => {
|
|
707
703
|
div.find("span").remove();
|
|
708
704
|
});
|
|
@@ -714,28 +710,28 @@ describe("jqLite", () => {
|
|
|
714
710
|
|
|
715
711
|
describe("camelCasing keys", () => {
|
|
716
712
|
it("should camelCase the key in a setter", () => {
|
|
717
|
-
const element =
|
|
713
|
+
const element = JQLite(a);
|
|
718
714
|
|
|
719
715
|
element.data("a-B-c-d-42--e", "z-x");
|
|
720
716
|
expect(element.data()).toEqual({ "a-BCD-42-E": "z-x" });
|
|
721
717
|
});
|
|
722
718
|
|
|
723
719
|
it("should camelCase the key in a getter", () => {
|
|
724
|
-
const element =
|
|
720
|
+
const element = JQLite(a);
|
|
725
721
|
|
|
726
722
|
element.data()["a-BCD-42-E"] = "x-c";
|
|
727
723
|
expect(element.data("a-B-c-d-42--e")).toBe("x-c");
|
|
728
724
|
});
|
|
729
725
|
|
|
730
726
|
it("should camelCase the key in a mass setter", () => {
|
|
731
|
-
const element =
|
|
727
|
+
const element = JQLite(a);
|
|
732
728
|
|
|
733
729
|
element.data({ "a-B-c-d-42--e": "c-v", "r-t-v": 42 });
|
|
734
730
|
expect(element.data()).toEqual({ "a-BCD-42-E": "c-v", rTV: 42 });
|
|
735
731
|
});
|
|
736
732
|
|
|
737
733
|
it("should ignore non-camelCase keys in the data in a getter", () => {
|
|
738
|
-
const element =
|
|
734
|
+
const element = JQLite(a);
|
|
739
735
|
|
|
740
736
|
element.data()["a-b"] = "b-n";
|
|
741
737
|
expect(element.data("a-b")).toBe(undefined);
|
|
@@ -745,36 +741,36 @@ describe("jqLite", () => {
|
|
|
745
741
|
|
|
746
742
|
describe("attr", () => {
|
|
747
743
|
it("should read, write and remove attr", () => {
|
|
748
|
-
const selector =
|
|
744
|
+
const selector = JQLite([a, b]);
|
|
749
745
|
|
|
750
746
|
expect(selector.attr("prop", "value")).toEqual(selector);
|
|
751
|
-
expect(
|
|
752
|
-
expect(
|
|
747
|
+
expect(JQLite(a).attr("prop")).toEqual("value");
|
|
748
|
+
expect(JQLite(b).attr("prop")).toEqual("value");
|
|
753
749
|
|
|
754
750
|
expect(selector.attr({ prop: "new value" })).toEqual(selector);
|
|
755
|
-
expect(
|
|
756
|
-
expect(
|
|
751
|
+
expect(JQLite(a).attr("prop")).toEqual("new value");
|
|
752
|
+
expect(JQLite(b).attr("prop")).toEqual("new value");
|
|
757
753
|
|
|
758
|
-
|
|
759
|
-
expect(
|
|
760
|
-
expect(
|
|
754
|
+
JQLite(b).attr({ prop: "new value 2" });
|
|
755
|
+
expect(JQLite(selector).attr("prop")).toEqual("new value");
|
|
756
|
+
expect(JQLite(b).attr("prop")).toEqual("new value 2");
|
|
761
757
|
|
|
762
758
|
selector[0].removeAttribute("prop");
|
|
763
759
|
selector[1].removeAttribute("prop");
|
|
764
|
-
expect(
|
|
765
|
-
expect(
|
|
760
|
+
expect(JQLite(a).attr("prop")).toBeFalsy();
|
|
761
|
+
expect(JQLite(b).attr("prop")).toBeFalsy();
|
|
766
762
|
});
|
|
767
763
|
|
|
768
764
|
it("should read boolean attributes as strings", () => {
|
|
769
|
-
const select =
|
|
765
|
+
const select = JQLite("<select>");
|
|
770
766
|
expect(select.attr("multiple")).toBeUndefined();
|
|
771
|
-
expect(
|
|
772
|
-
expect(
|
|
773
|
-
expect(
|
|
767
|
+
expect(JQLite("<select multiple>").attr("multiple")).toBe("multiple");
|
|
768
|
+
expect(JQLite('<select multiple="">').attr("multiple")).toBe("multiple");
|
|
769
|
+
expect(JQLite('<select multiple="x">').attr("multiple")).toBe("multiple");
|
|
774
770
|
});
|
|
775
771
|
|
|
776
772
|
it("should add/remove boolean attributes", () => {
|
|
777
|
-
const select =
|
|
773
|
+
const select = JQLite("<select>");
|
|
778
774
|
select.attr("multiple", false);
|
|
779
775
|
expect(select.attr("multiple")).toBeUndefined();
|
|
780
776
|
|
|
@@ -785,7 +781,7 @@ describe("jqLite", () => {
|
|
|
785
781
|
it("should not take properties into account when getting respective boolean attributes", () => {
|
|
786
782
|
// Use a div and not a select as the latter would itself reflect the multiple attribute
|
|
787
783
|
// to a property.
|
|
788
|
-
const div =
|
|
784
|
+
const div = JQLite("<div>");
|
|
789
785
|
|
|
790
786
|
div[0].multiple = true;
|
|
791
787
|
expect(div.attr("multiple")).toBe(undefined);
|
|
@@ -798,7 +794,7 @@ describe("jqLite", () => {
|
|
|
798
794
|
it("should not set properties when setting respective boolean attributes", () => {
|
|
799
795
|
// Use a div and not a select as the latter would itself reflect the multiple attribute
|
|
800
796
|
// to a property.
|
|
801
|
-
const div =
|
|
797
|
+
const div = JQLite("<div>");
|
|
802
798
|
|
|
803
799
|
// Check the initial state.
|
|
804
800
|
expect(div[0].multiple).toBe(undefined);
|
|
@@ -817,7 +813,7 @@ describe("jqLite", () => {
|
|
|
817
813
|
});
|
|
818
814
|
|
|
819
815
|
it("should normalize the case of boolean attributes", () => {
|
|
820
|
-
const input =
|
|
816
|
+
const input = JQLite("<input readonly>");
|
|
821
817
|
expect(input.attr("readonly")).toBe("readonly");
|
|
822
818
|
expect(input.attr("readOnly")).toBe("readonly");
|
|
823
819
|
expect(input.attr("READONLY")).toBe("readonly");
|
|
@@ -831,19 +827,19 @@ describe("jqLite", () => {
|
|
|
831
827
|
});
|
|
832
828
|
|
|
833
829
|
it("should return undefined for non-existing attributes", () => {
|
|
834
|
-
const elm =
|
|
830
|
+
const elm = JQLite('<div class="any">a</div>');
|
|
835
831
|
expect(elm.attr("non-existing")).toBeUndefined();
|
|
836
832
|
});
|
|
837
833
|
|
|
838
834
|
it("should return undefined for non-existing attributes on input", () => {
|
|
839
|
-
const elm =
|
|
835
|
+
const elm = JQLite("<input>");
|
|
840
836
|
expect(elm.attr("readonly")).toBeUndefined();
|
|
841
837
|
expect(elm.attr("readOnly")).toBeUndefined();
|
|
842
838
|
expect(elm.attr("disabled")).toBeUndefined();
|
|
843
839
|
});
|
|
844
840
|
|
|
845
841
|
it("should do nothing when setting or getting on attribute nodes", () => {
|
|
846
|
-
const attrNode =
|
|
842
|
+
const attrNode = JQLite(window.document.createAttribute("myattr"));
|
|
847
843
|
expect(attrNode).toBeDefined();
|
|
848
844
|
expect(attrNode[0].nodeType).toEqual(2);
|
|
849
845
|
expect(attrNode.attr("some-attribute", "somevalue")).toEqual(attrNode);
|
|
@@ -851,7 +847,7 @@ describe("jqLite", () => {
|
|
|
851
847
|
});
|
|
852
848
|
|
|
853
849
|
it("should do nothing when setting or getting on text nodes", () => {
|
|
854
|
-
const textNode =
|
|
850
|
+
const textNode = JQLite(window.document.createTextNode("some text"));
|
|
855
851
|
expect(textNode).toBeDefined();
|
|
856
852
|
expect(textNode[0].nodeType).toEqual(3);
|
|
857
853
|
expect(textNode.attr("some-attribute", "somevalue")).toEqual(textNode);
|
|
@@ -859,7 +855,7 @@ describe("jqLite", () => {
|
|
|
859
855
|
});
|
|
860
856
|
|
|
861
857
|
it("should do nothing when setting or getting on comment nodes", () => {
|
|
862
|
-
const comment =
|
|
858
|
+
const comment = JQLite(window.document.createComment("some comment"));
|
|
863
859
|
expect(comment).toBeDefined();
|
|
864
860
|
expect(comment[0].nodeType).toEqual(8);
|
|
865
861
|
expect(comment.attr("some-attribute", "somevalue")).toEqual(comment);
|
|
@@ -867,31 +863,31 @@ describe("jqLite", () => {
|
|
|
867
863
|
});
|
|
868
864
|
|
|
869
865
|
it("should remove the attribute for a null value", () => {
|
|
870
|
-
const elm =
|
|
866
|
+
const elm = JQLite('<div attribute="value">a</div>');
|
|
871
867
|
elm.attr("attribute", null);
|
|
872
868
|
expect(elm[0].hasAttribute("attribute")).toBe(false);
|
|
873
869
|
});
|
|
874
870
|
|
|
875
871
|
it("should not remove the attribute for an empty string as a value", () => {
|
|
876
|
-
const elm =
|
|
872
|
+
const elm = JQLite('<div attribute="value">a</div>');
|
|
877
873
|
elm.attr("attribute", "");
|
|
878
874
|
expect(elm[0].getAttribute("attribute")).toBe("");
|
|
879
875
|
});
|
|
880
876
|
|
|
881
877
|
it("should remove the boolean attribute for a false value", () => {
|
|
882
|
-
const elm =
|
|
878
|
+
const elm = JQLite("<select multiple>");
|
|
883
879
|
elm.attr("multiple", false);
|
|
884
880
|
expect(elm[0].hasAttribute("multiple")).toBe(false);
|
|
885
881
|
});
|
|
886
882
|
|
|
887
883
|
it("should remove the boolean attribute for a null value", () => {
|
|
888
|
-
const elm =
|
|
884
|
+
const elm = JQLite("<select multiple>");
|
|
889
885
|
elm.attr("multiple", null);
|
|
890
886
|
expect(elm[0].hasAttribute("multiple")).toBe(false);
|
|
891
887
|
});
|
|
892
888
|
|
|
893
889
|
it("should not remove the boolean attribute for an empty string as a value", () => {
|
|
894
|
-
const elm =
|
|
890
|
+
const elm = JQLite("<select multiple>");
|
|
895
891
|
elm.attr("multiple", "");
|
|
896
892
|
expect(elm[0].getAttribute("multiple")).toBe("multiple");
|
|
897
893
|
});
|
|
@@ -899,7 +895,7 @@ describe("jqLite", () => {
|
|
|
899
895
|
it("should not fail on elements without the getAttribute method", () => {
|
|
900
896
|
forEach([window, document], (node) => {
|
|
901
897
|
expect(() => {
|
|
902
|
-
const elem =
|
|
898
|
+
const elem = JQLite(node);
|
|
903
899
|
elem.attr("foo");
|
|
904
900
|
elem.attr("bar", "baz");
|
|
905
901
|
elem.attr("bar");
|
|
@@ -910,12 +906,12 @@ describe("jqLite", () => {
|
|
|
910
906
|
|
|
911
907
|
describe("text", () => {
|
|
912
908
|
it('should return `""` on empty', () => {
|
|
913
|
-
expect(
|
|
914
|
-
expect(
|
|
909
|
+
expect(JQLite().length).toEqual(0);
|
|
910
|
+
expect(JQLite().text()).toEqual("");
|
|
915
911
|
});
|
|
916
912
|
|
|
917
913
|
it("should read/write value", () => {
|
|
918
|
-
const element =
|
|
914
|
+
const element = JQLite("<div>ab</div><span>c</span>");
|
|
919
915
|
expect(element.length).toEqual(2);
|
|
920
916
|
expect(element[0].innerHTML).toEqual("ab");
|
|
921
917
|
expect(element[1].innerHTML).toEqual("c");
|
|
@@ -925,14 +921,14 @@ describe("jqLite", () => {
|
|
|
925
921
|
});
|
|
926
922
|
|
|
927
923
|
it("should return text only for element or text nodes", () => {
|
|
928
|
-
expect(
|
|
929
|
-
expect(
|
|
924
|
+
expect(JQLite("<div>foo</div>").text()).toBe("foo");
|
|
925
|
+
expect(JQLite(window.document.createComment("foo")).text()).toBe("");
|
|
930
926
|
});
|
|
931
927
|
});
|
|
932
928
|
|
|
933
929
|
describe("val", () => {
|
|
934
930
|
it("should read, write value", () => {
|
|
935
|
-
const input =
|
|
931
|
+
const input = JQLite('<input type="text"/>');
|
|
936
932
|
expect(input.val("abc")).toEqual(input);
|
|
937
933
|
expect(input[0].value).toEqual("abc");
|
|
938
934
|
expect(input.val()).toEqual("abc");
|
|
@@ -940,7 +936,7 @@ describe("jqLite", () => {
|
|
|
940
936
|
|
|
941
937
|
it("should get an array of selected elements from a multi select", () => {
|
|
942
938
|
expect(
|
|
943
|
-
|
|
939
|
+
JQLite(
|
|
944
940
|
"<select multiple>" +
|
|
945
941
|
"<option selected>test 1</option>" +
|
|
946
942
|
"<option selected>test 2</option>" +
|
|
@@ -949,7 +945,7 @@ describe("jqLite", () => {
|
|
|
949
945
|
).toEqual(["test 1", "test 2"]);
|
|
950
946
|
|
|
951
947
|
expect(
|
|
952
|
-
|
|
948
|
+
JQLite(
|
|
953
949
|
"<select multiple>" +
|
|
954
950
|
"<option selected>test 1</option>" +
|
|
955
951
|
"<option>test 2</option>" +
|
|
@@ -960,7 +956,7 @@ describe("jqLite", () => {
|
|
|
960
956
|
// In jQuery < 3.0 .val() on select[multiple] with no selected options returns an
|
|
961
957
|
// null instead of an empty array.
|
|
962
958
|
expect(
|
|
963
|
-
|
|
959
|
+
JQLite(
|
|
964
960
|
"<select multiple>" +
|
|
965
961
|
"<option>test 1</option>" +
|
|
966
962
|
"<option>test 2</option>" +
|
|
@@ -975,7 +971,7 @@ describe("jqLite", () => {
|
|
|
975
971
|
// See https://github.com/jquery/jquery/issues/2562 for more details.
|
|
976
972
|
|
|
977
973
|
expect(
|
|
978
|
-
|
|
974
|
+
JQLite(
|
|
979
975
|
"<select multiple>" +
|
|
980
976
|
"<optgroup>" +
|
|
981
977
|
"<option>test 1</option>" +
|
|
@@ -987,7 +983,7 @@ describe("jqLite", () => {
|
|
|
987
983
|
).toEqual([]);
|
|
988
984
|
|
|
989
985
|
expect(
|
|
990
|
-
|
|
986
|
+
JQLite(
|
|
991
987
|
"<select multiple>" +
|
|
992
988
|
"<optgroup disabled>" +
|
|
993
989
|
"<option>test 1</option>" +
|
|
@@ -1002,12 +998,12 @@ describe("jqLite", () => {
|
|
|
1002
998
|
|
|
1003
999
|
describe("html", () => {
|
|
1004
1000
|
it("should return `undefined` on empty", () => {
|
|
1005
|
-
expect(
|
|
1006
|
-
expect(
|
|
1001
|
+
expect(JQLite().length).toEqual(0);
|
|
1002
|
+
expect(JQLite().html()).toEqual(undefined);
|
|
1007
1003
|
});
|
|
1008
1004
|
|
|
1009
1005
|
it("should read/write a value", () => {
|
|
1010
|
-
const element =
|
|
1006
|
+
const element = JQLite("<div>abc</div>");
|
|
1011
1007
|
expect(element.length).toEqual(1);
|
|
1012
1008
|
expect(element[0].innerHTML).toEqual("abc");
|
|
1013
1009
|
expect(element.html()).toEqual("abc");
|
|
@@ -1018,7 +1014,7 @@ describe("jqLite", () => {
|
|
|
1018
1014
|
|
|
1019
1015
|
describe("empty", () => {
|
|
1020
1016
|
it("should write a value", () => {
|
|
1021
|
-
const element =
|
|
1017
|
+
const element = JQLite("<div>abc</div>");
|
|
1022
1018
|
expect(element.length).toEqual(1);
|
|
1023
1019
|
expect(element.empty() === element).toBeTruthy();
|
|
1024
1020
|
expect(element.html()).toEqual("");
|
|
@@ -1043,7 +1039,7 @@ describe("jqLite", () => {
|
|
|
1043
1039
|
window.window = window;
|
|
1044
1040
|
|
|
1045
1041
|
let log;
|
|
1046
|
-
const jWindow =
|
|
1042
|
+
const jWindow = JQLite(window).on("hashchange", () => {
|
|
1047
1043
|
log = "works!";
|
|
1048
1044
|
});
|
|
1049
1045
|
eventFn({ type: "hashchange" });
|
|
@@ -1052,11 +1048,11 @@ describe("jqLite", () => {
|
|
|
1052
1048
|
});
|
|
1053
1049
|
|
|
1054
1050
|
it("should bind to all elements and return functions", () => {
|
|
1055
|
-
const selected =
|
|
1051
|
+
const selected = JQLite([a, b]);
|
|
1056
1052
|
let log = "";
|
|
1057
1053
|
expect(
|
|
1058
1054
|
selected.on("click", function () {
|
|
1059
|
-
log += `click on: ${
|
|
1055
|
+
log += `click on: ${JQLite(this).text()};`;
|
|
1060
1056
|
}),
|
|
1061
1057
|
).toEqual(selected);
|
|
1062
1058
|
browserTrigger(a, "click");
|
|
@@ -1066,7 +1062,7 @@ describe("jqLite", () => {
|
|
|
1066
1062
|
});
|
|
1067
1063
|
|
|
1068
1064
|
it("should not bind to comment or text nodes", () => {
|
|
1069
|
-
const nodes =
|
|
1065
|
+
const nodes = JQLite("<!-- some comment -->Some text");
|
|
1070
1066
|
const someEventHandler = jasmine.createSpy("someEventHandler");
|
|
1071
1067
|
|
|
1072
1068
|
nodes.on("someEvent", someEventHandler);
|
|
@@ -1076,7 +1072,7 @@ describe("jqLite", () => {
|
|
|
1076
1072
|
});
|
|
1077
1073
|
|
|
1078
1074
|
it("should bind to all events separated by space", () => {
|
|
1079
|
-
const elm =
|
|
1075
|
+
const elm = JQLite(a);
|
|
1080
1076
|
const callback = jasmine.createSpy("callback");
|
|
1081
1077
|
|
|
1082
1078
|
elm.on("click keypress", callback);
|
|
@@ -1093,7 +1089,7 @@ describe("jqLite", () => {
|
|
|
1093
1089
|
});
|
|
1094
1090
|
|
|
1095
1091
|
it("should set event.target", () => {
|
|
1096
|
-
const elm =
|
|
1092
|
+
const elm = JQLite(a);
|
|
1097
1093
|
elm.on("click", (event) => {
|
|
1098
1094
|
expect(event.target).toBe(a);
|
|
1099
1095
|
});
|
|
@@ -1102,7 +1098,7 @@ describe("jqLite", () => {
|
|
|
1102
1098
|
});
|
|
1103
1099
|
|
|
1104
1100
|
it("should have event.isDefaultPrevented method", () => {
|
|
1105
|
-
const element =
|
|
1101
|
+
const element = JQLite(a);
|
|
1106
1102
|
|
|
1107
1103
|
element.on("click", (e) => {
|
|
1108
1104
|
expect(e.isDefaultPrevented()).toBe(false);
|
|
@@ -1114,7 +1110,7 @@ describe("jqLite", () => {
|
|
|
1114
1110
|
});
|
|
1115
1111
|
|
|
1116
1112
|
it("should stop triggering handlers when stopImmediatePropagation is called", () => {
|
|
1117
|
-
const element =
|
|
1113
|
+
const element = JQLite(a);
|
|
1118
1114
|
const clickSpy1 = jasmine.createSpy("clickSpy1");
|
|
1119
1115
|
const clickSpy2 = jasmine.createSpy("clickSpy2").and.callFake((event) => {
|
|
1120
1116
|
event.stopImmediatePropagation();
|
|
@@ -1136,7 +1132,7 @@ describe("jqLite", () => {
|
|
|
1136
1132
|
});
|
|
1137
1133
|
|
|
1138
1134
|
it("should execute stopPropagation when stopImmediatePropagation is called", () => {
|
|
1139
|
-
const element =
|
|
1135
|
+
const element = JQLite(a);
|
|
1140
1136
|
const clickSpy = jasmine.createSpy("clickSpy");
|
|
1141
1137
|
|
|
1142
1138
|
clickSpy.and.callFake((event) => {
|
|
@@ -1152,7 +1148,7 @@ describe("jqLite", () => {
|
|
|
1152
1148
|
});
|
|
1153
1149
|
|
|
1154
1150
|
it("should have event.isImmediatePropagationStopped method", () => {
|
|
1155
|
-
const element =
|
|
1151
|
+
const element = JQLite(a);
|
|
1156
1152
|
const clickSpy = jasmine.createSpy("clickSpy");
|
|
1157
1153
|
|
|
1158
1154
|
clickSpy.and.callFake((event) => {
|
|
@@ -1175,7 +1171,7 @@ describe("jqLite", () => {
|
|
|
1175
1171
|
|
|
1176
1172
|
function setup(html, parentNode, childNode) {
|
|
1177
1173
|
log = "";
|
|
1178
|
-
root =
|
|
1174
|
+
root = JQLite(html);
|
|
1179
1175
|
parent = root.find(parentNode);
|
|
1180
1176
|
child = parent.find(childNode);
|
|
1181
1177
|
|
|
@@ -1280,7 +1276,7 @@ describe("jqLite", () => {
|
|
|
1280
1276
|
});
|
|
1281
1277
|
|
|
1282
1278
|
it("should throw an error if eventData or a selector is passed", () => {
|
|
1283
|
-
const elm =
|
|
1279
|
+
const elm = JQLite(a);
|
|
1284
1280
|
const anObj = {};
|
|
1285
1281
|
const aString = "";
|
|
1286
1282
|
const aValue = 45;
|
|
@@ -1302,7 +1298,7 @@ describe("jqLite", () => {
|
|
|
1302
1298
|
|
|
1303
1299
|
describe("off", () => {
|
|
1304
1300
|
it("should do nothing when no listener was registered with bound", () => {
|
|
1305
|
-
const aElem =
|
|
1301
|
+
const aElem = JQLite(a);
|
|
1306
1302
|
|
|
1307
1303
|
aElem.off();
|
|
1308
1304
|
aElem.off("click");
|
|
@@ -1310,14 +1306,14 @@ describe("jqLite", () => {
|
|
|
1310
1306
|
});
|
|
1311
1307
|
|
|
1312
1308
|
it("should do nothing when a specific listener was not registered", () => {
|
|
1313
|
-
const aElem =
|
|
1309
|
+
const aElem = JQLite(a);
|
|
1314
1310
|
aElem.on("click", () => {});
|
|
1315
1311
|
|
|
1316
1312
|
aElem.off("mouseenter", () => {});
|
|
1317
1313
|
});
|
|
1318
1314
|
|
|
1319
1315
|
it("should deregister all listeners", () => {
|
|
1320
|
-
const aElem =
|
|
1316
|
+
const aElem = JQLite(a);
|
|
1321
1317
|
const clickSpy = jasmine.createSpy("click");
|
|
1322
1318
|
const mouseoverSpy = jasmine.createSpy("mouseover");
|
|
1323
1319
|
|
|
@@ -1341,7 +1337,7 @@ describe("jqLite", () => {
|
|
|
1341
1337
|
});
|
|
1342
1338
|
|
|
1343
1339
|
it("should deregister listeners for specific type", () => {
|
|
1344
|
-
const aElem =
|
|
1340
|
+
const aElem = JQLite(a);
|
|
1345
1341
|
const clickSpy = jasmine.createSpy("click");
|
|
1346
1342
|
const mouseoverSpy = jasmine.createSpy("mouseover");
|
|
1347
1343
|
|
|
@@ -1371,7 +1367,7 @@ describe("jqLite", () => {
|
|
|
1371
1367
|
});
|
|
1372
1368
|
|
|
1373
1369
|
it("should deregister all listeners for types separated by spaces", () => {
|
|
1374
|
-
const aElem =
|
|
1370
|
+
const aElem = JQLite(a);
|
|
1375
1371
|
const clickSpy = jasmine.createSpy("click");
|
|
1376
1372
|
const mouseoverSpy = jasmine.createSpy("mouseover");
|
|
1377
1373
|
|
|
@@ -1395,7 +1391,7 @@ describe("jqLite", () => {
|
|
|
1395
1391
|
});
|
|
1396
1392
|
|
|
1397
1393
|
it("should deregister specific listener", () => {
|
|
1398
|
-
const aElem =
|
|
1394
|
+
const aElem = JQLite(a);
|
|
1399
1395
|
const clickSpy1 = jasmine.createSpy("click1");
|
|
1400
1396
|
const clickSpy2 = jasmine.createSpy("click2");
|
|
1401
1397
|
|
|
@@ -1423,7 +1419,7 @@ describe("jqLite", () => {
|
|
|
1423
1419
|
});
|
|
1424
1420
|
|
|
1425
1421
|
it("should correctly deregister the mouseenter/mouseleave listeners", () => {
|
|
1426
|
-
const aElem =
|
|
1422
|
+
const aElem = JQLite(a);
|
|
1427
1423
|
const onMouseenter = jasmine.createSpy("onMouseenter");
|
|
1428
1424
|
const onMouseleave = jasmine.createSpy("onMouseleave");
|
|
1429
1425
|
|
|
@@ -1445,7 +1441,7 @@ describe("jqLite", () => {
|
|
|
1445
1441
|
"should call a `mouseenter/leave` listener only once when `mouseenter/leave` and `mouseover/out` " +
|
|
1446
1442
|
"are triggered simultaneously",
|
|
1447
1443
|
() => {
|
|
1448
|
-
const aElem =
|
|
1444
|
+
const aElem = JQLite(a);
|
|
1449
1445
|
const onMouseenter = jasmine.createSpy("mouseenter");
|
|
1450
1446
|
const onMouseleave = jasmine.createSpy("mouseleave");
|
|
1451
1447
|
|
|
@@ -1463,7 +1459,7 @@ describe("jqLite", () => {
|
|
|
1463
1459
|
);
|
|
1464
1460
|
|
|
1465
1461
|
it("should call a `mouseenter/leave` listener when manually triggering the event", () => {
|
|
1466
|
-
const aElem =
|
|
1462
|
+
const aElem = JQLite(a);
|
|
1467
1463
|
const onMouseenter = jasmine.createSpy("mouseenter");
|
|
1468
1464
|
const onMouseleave = jasmine.createSpy("mouseleave");
|
|
1469
1465
|
|
|
@@ -1478,7 +1474,7 @@ describe("jqLite", () => {
|
|
|
1478
1474
|
});
|
|
1479
1475
|
|
|
1480
1476
|
it("should deregister specific listener within the listener and call subsequent listeners", () => {
|
|
1481
|
-
const aElem =
|
|
1477
|
+
const aElem = JQLite(a);
|
|
1482
1478
|
const clickSpy = jasmine.createSpy("click");
|
|
1483
1479
|
const clickOnceSpy = jasmine.createSpy("clickOnce").and.callFake(() => {
|
|
1484
1480
|
aElem.off("click", clickOnceSpy);
|
|
@@ -1497,7 +1493,7 @@ describe("jqLite", () => {
|
|
|
1497
1493
|
});
|
|
1498
1494
|
|
|
1499
1495
|
it("should deregister specific listener for multiple types separated by spaces", () => {
|
|
1500
|
-
const aElem =
|
|
1496
|
+
const aElem = JQLite(a);
|
|
1501
1497
|
const leaderSpy = jasmine.createSpy("leader");
|
|
1502
1498
|
const extraSpy = jasmine.createSpy("extra");
|
|
1503
1499
|
|
|
@@ -1523,10 +1519,10 @@ describe("jqLite", () => {
|
|
|
1523
1519
|
|
|
1524
1520
|
describe("native listener deregistration", () => {
|
|
1525
1521
|
it(
|
|
1526
|
-
"should deregister the native listener when all
|
|
1522
|
+
"should deregister the native listener when all JQLite listeners for given type are gone " +
|
|
1527
1523
|
'after off("eventName", listener) call',
|
|
1528
1524
|
() => {
|
|
1529
|
-
const aElem =
|
|
1525
|
+
const aElem = JQLite(a);
|
|
1530
1526
|
const addEventListenerSpy = spyOn(
|
|
1531
1527
|
aElem[0],
|
|
1532
1528
|
"addEventListener",
|
|
@@ -1537,8 +1533,8 @@ describe("jqLite", () => {
|
|
|
1537
1533
|
).and.callThrough();
|
|
1538
1534
|
let nativeListenerFn;
|
|
1539
1535
|
|
|
1540
|
-
const
|
|
1541
|
-
aElem.on("click",
|
|
1536
|
+
const JQLiteListener = () => {};
|
|
1537
|
+
aElem.on("click", JQLiteListener);
|
|
1542
1538
|
|
|
1543
1539
|
expect(addEventListenerSpy).toHaveBeenCalledOnceWith(
|
|
1544
1540
|
"click",
|
|
@@ -1547,7 +1543,7 @@ describe("jqLite", () => {
|
|
|
1547
1543
|
nativeListenerFn = addEventListenerSpy.calls.mostRecent().args[1];
|
|
1548
1544
|
expect(removeEventListenerSpy).not.toHaveBeenCalled();
|
|
1549
1545
|
|
|
1550
|
-
aElem.off("click",
|
|
1546
|
+
aElem.off("click", JQLiteListener);
|
|
1551
1547
|
expect(removeEventListenerSpy).toHaveBeenCalledOnceWith(
|
|
1552
1548
|
"click",
|
|
1553
1549
|
nativeListenerFn,
|
|
@@ -1556,10 +1552,10 @@ describe("jqLite", () => {
|
|
|
1556
1552
|
);
|
|
1557
1553
|
|
|
1558
1554
|
it(
|
|
1559
|
-
"should deregister the native listener when all
|
|
1555
|
+
"should deregister the native listener when all JQLite listeners for given type are gone " +
|
|
1560
1556
|
'after off("eventName") call',
|
|
1561
1557
|
() => {
|
|
1562
|
-
const aElem =
|
|
1558
|
+
const aElem = JQLite(a);
|
|
1563
1559
|
const addEventListenerSpy = spyOn(
|
|
1564
1560
|
aElem[0],
|
|
1565
1561
|
"addEventListener",
|
|
@@ -1587,10 +1583,10 @@ describe("jqLite", () => {
|
|
|
1587
1583
|
);
|
|
1588
1584
|
|
|
1589
1585
|
it(
|
|
1590
|
-
"should deregister the native listener when all
|
|
1586
|
+
"should deregister the native listener when all JQLite listeners for given type are gone " +
|
|
1591
1587
|
'after off("eventName1 eventName2") call',
|
|
1592
1588
|
() => {
|
|
1593
|
-
const aElem =
|
|
1589
|
+
const aElem = JQLite(a);
|
|
1594
1590
|
const addEventListenerSpy = spyOn(
|
|
1595
1591
|
aElem[0],
|
|
1596
1592
|
"addEventListener",
|
|
@@ -1632,10 +1628,10 @@ describe("jqLite", () => {
|
|
|
1632
1628
|
);
|
|
1633
1629
|
|
|
1634
1630
|
it(
|
|
1635
|
-
"should deregister the native listener when all
|
|
1631
|
+
"should deregister the native listener when all JQLite listeners for given type are gone " +
|
|
1636
1632
|
"after off() call",
|
|
1637
1633
|
() => {
|
|
1638
|
-
const aElem =
|
|
1634
|
+
const aElem = JQLite(a);
|
|
1639
1635
|
const addEventListenerSpy = spyOn(
|
|
1640
1636
|
aElem[0],
|
|
1641
1637
|
"addEventListener",
|
|
@@ -1676,7 +1672,7 @@ describe("jqLite", () => {
|
|
|
1676
1672
|
});
|
|
1677
1673
|
|
|
1678
1674
|
it("should throw an error if a selector is passed", () => {
|
|
1679
|
-
const aElem =
|
|
1675
|
+
const aElem = JQLite(a);
|
|
1680
1676
|
aElem.on("click", () => {});
|
|
1681
1677
|
expect(() => {
|
|
1682
1678
|
aElem.off("click", () => {}, ".test");
|
|
@@ -1686,14 +1682,14 @@ describe("jqLite", () => {
|
|
|
1686
1682
|
|
|
1687
1683
|
describe("replaceWith", () => {
|
|
1688
1684
|
it("should replaceWith", () => {
|
|
1689
|
-
const root =
|
|
1685
|
+
const root = JQLite("<div>").html("before-<div></div>after");
|
|
1690
1686
|
const div = root.find("div");
|
|
1691
1687
|
expect(div.replaceWith("<span>span-</span><b>bold-</b>")).toEqual(div);
|
|
1692
1688
|
expect(root.text()).toEqual("before-span-bold-after");
|
|
1693
1689
|
});
|
|
1694
1690
|
|
|
1695
1691
|
it("should replaceWith text", () => {
|
|
1696
|
-
const root =
|
|
1692
|
+
const root = JQLite("<div>").html("before-<div></div>after");
|
|
1697
1693
|
const div = root.find("div");
|
|
1698
1694
|
expect(div.replaceWith("text-")).toEqual(div);
|
|
1699
1695
|
expect(root.text()).toEqual("before-text-after");
|
|
@@ -1702,7 +1698,7 @@ describe("jqLite", () => {
|
|
|
1702
1698
|
|
|
1703
1699
|
describe("children", () => {
|
|
1704
1700
|
it("should only select element nodes", () => {
|
|
1705
|
-
const root =
|
|
1701
|
+
const root = JQLite(
|
|
1706
1702
|
"<div><!-- some comment -->before-<div></div>after-<span></span>",
|
|
1707
1703
|
);
|
|
1708
1704
|
const div = root.find("div");
|
|
@@ -1713,22 +1709,22 @@ describe("jqLite", () => {
|
|
|
1713
1709
|
|
|
1714
1710
|
describe("append", () => {
|
|
1715
1711
|
it("should append", () => {
|
|
1716
|
-
const root =
|
|
1712
|
+
const root = JQLite("<div>");
|
|
1717
1713
|
expect(root.append("<span>abc</span>")).toEqual(root);
|
|
1718
1714
|
expect(root.html().toLowerCase()).toEqual("<span>abc</span>");
|
|
1719
1715
|
});
|
|
1720
1716
|
it("should append text", () => {
|
|
1721
|
-
const root =
|
|
1717
|
+
const root = JQLite("<div>");
|
|
1722
1718
|
expect(root.append("text")).toEqual(root);
|
|
1723
1719
|
expect(root.html()).toEqual("text");
|
|
1724
1720
|
});
|
|
1725
1721
|
it("should append to document fragment", () => {
|
|
1726
|
-
const root =
|
|
1722
|
+
const root = JQLite(window.document.createDocumentFragment());
|
|
1727
1723
|
expect(root.append("<p>foo</p>")).toBe(root);
|
|
1728
1724
|
expect(root.children().length).toBe(1);
|
|
1729
1725
|
});
|
|
1730
1726
|
it("should not append anything if parent node is not of type element or docfrag", () => {
|
|
1731
|
-
const root =
|
|
1727
|
+
const root = JQLite(JQLite("<p>some text node</p>")[0].childNodes);
|
|
1732
1728
|
expect(root.append("<p>foo</p>")).toBe(root);
|
|
1733
1729
|
expect(root.children().length).toBe(0);
|
|
1734
1730
|
});
|
|
@@ -1736,27 +1732,27 @@ describe("jqLite", () => {
|
|
|
1736
1732
|
|
|
1737
1733
|
describe("prepend", () => {
|
|
1738
1734
|
it("should prepend to empty", () => {
|
|
1739
|
-
const root =
|
|
1735
|
+
const root = JQLite("<div>");
|
|
1740
1736
|
expect(root.prepend("<span>abc</span>")).toEqual(root);
|
|
1741
1737
|
expect(root.html().toLowerCase()).toEqual("<span>abc</span>");
|
|
1742
1738
|
});
|
|
1743
1739
|
it("should prepend to content", () => {
|
|
1744
|
-
const root =
|
|
1740
|
+
const root = JQLite("<div>text</div>");
|
|
1745
1741
|
expect(root.prepend("<span>abc</span>")).toEqual(root);
|
|
1746
1742
|
expect(root.html().toLowerCase()).toEqual("<span>abc</span>text");
|
|
1747
1743
|
});
|
|
1748
1744
|
it("should prepend text to content", () => {
|
|
1749
|
-
const root =
|
|
1745
|
+
const root = JQLite("<div>text</div>");
|
|
1750
1746
|
expect(root.prepend("abc")).toEqual(root);
|
|
1751
1747
|
expect(root.html().toLowerCase()).toEqual("abctext");
|
|
1752
1748
|
});
|
|
1753
1749
|
it("should prepend array to empty in the right order", () => {
|
|
1754
|
-
const root =
|
|
1750
|
+
const root = JQLite("<div>");
|
|
1755
1751
|
expect(root.prepend([a, b, c])).toBe(root);
|
|
1756
1752
|
expect(root.html()).toEqual("<div>A</div><div>B</div><div>C</div>");
|
|
1757
1753
|
});
|
|
1758
1754
|
it("should prepend array to content in the right order", () => {
|
|
1759
|
-
const root =
|
|
1755
|
+
const root = JQLite("<div>text</div>");
|
|
1760
1756
|
expect(root.prepend([a, b, c])).toBe(root);
|
|
1761
1757
|
expect(root.html()).toBe("<div>A</div><div>B</div><div>C</div>text");
|
|
1762
1758
|
});
|
|
@@ -1764,7 +1760,7 @@ describe("jqLite", () => {
|
|
|
1764
1760
|
|
|
1765
1761
|
describe("remove", () => {
|
|
1766
1762
|
it("should remove", () => {
|
|
1767
|
-
const root =
|
|
1763
|
+
const root = JQLite("<div><span>abc</span></div>");
|
|
1768
1764
|
const span = root.find("span");
|
|
1769
1765
|
expect(span.remove()).toEqual(span);
|
|
1770
1766
|
expect(root.html()).toEqual("");
|
|
@@ -1773,7 +1769,7 @@ describe("jqLite", () => {
|
|
|
1773
1769
|
|
|
1774
1770
|
describe("detach", () => {
|
|
1775
1771
|
it("should detach", () => {
|
|
1776
|
-
const root =
|
|
1772
|
+
const root = JQLite("<div><span>abc</span></div>");
|
|
1777
1773
|
const span = root.find("span");
|
|
1778
1774
|
expect(span.detach()).toEqual(span);
|
|
1779
1775
|
expect(root.html()).toEqual("");
|
|
@@ -1782,21 +1778,21 @@ describe("jqLite", () => {
|
|
|
1782
1778
|
|
|
1783
1779
|
describe("after", () => {
|
|
1784
1780
|
it("should after", () => {
|
|
1785
|
-
const root =
|
|
1781
|
+
const root = JQLite("<div><span></span></div>");
|
|
1786
1782
|
const span = root.find("span");
|
|
1787
1783
|
expect(span.after("<i></i><b></b>")).toEqual(span);
|
|
1788
1784
|
expect(root.html().toLowerCase()).toEqual("<span></span><i></i><b></b>");
|
|
1789
1785
|
});
|
|
1790
1786
|
|
|
1791
1787
|
it("should allow taking text", () => {
|
|
1792
|
-
const root =
|
|
1788
|
+
const root = JQLite("<div><span></span></div>");
|
|
1793
1789
|
const span = root.find("span");
|
|
1794
1790
|
span.after("abc");
|
|
1795
1791
|
expect(root.html().toLowerCase()).toEqual("<span></span>abc");
|
|
1796
1792
|
});
|
|
1797
1793
|
|
|
1798
1794
|
it("should not throw when the element has no parent", () => {
|
|
1799
|
-
const span =
|
|
1795
|
+
const span = JQLite("<span></span>");
|
|
1800
1796
|
expect(() => {
|
|
1801
1797
|
span.after("abc");
|
|
1802
1798
|
}).not.toThrow();
|
|
@@ -1807,7 +1803,7 @@ describe("jqLite", () => {
|
|
|
1807
1803
|
|
|
1808
1804
|
describe("parent", () => {
|
|
1809
1805
|
it("should return parent or an empty set when no parent", () => {
|
|
1810
|
-
const parent =
|
|
1806
|
+
const parent = JQLite("<div><p>abc</p></div>");
|
|
1811
1807
|
const child = parent.find("p");
|
|
1812
1808
|
|
|
1813
1809
|
expect(parent.parent()).toBeTruthy();
|
|
@@ -1818,15 +1814,15 @@ describe("jqLite", () => {
|
|
|
1818
1814
|
});
|
|
1819
1815
|
|
|
1820
1816
|
it("should return empty set when no parent", () => {
|
|
1821
|
-
const element =
|
|
1817
|
+
const element = JQLite("<div>abc</div>");
|
|
1822
1818
|
expect(element.parent()).toBeTruthy();
|
|
1823
1819
|
expect(element.parent().length).toEqual(0);
|
|
1824
1820
|
});
|
|
1825
1821
|
|
|
1826
|
-
it("should return empty
|
|
1822
|
+
it("should return empty JQLite object when parent is a document fragment", () => {
|
|
1827
1823
|
// this is quite unfortunate but jQuery 1.5.1 behaves this way
|
|
1828
1824
|
const fragment = window.document.createDocumentFragment();
|
|
1829
|
-
const child =
|
|
1825
|
+
const child = JQLite("<p>foo</p>");
|
|
1830
1826
|
|
|
1831
1827
|
fragment.appendChild(child[0]);
|
|
1832
1828
|
expect(child[0].parentNode).toBe(fragment);
|
|
@@ -1836,14 +1832,14 @@ describe("jqLite", () => {
|
|
|
1836
1832
|
|
|
1837
1833
|
describe("find", () => {
|
|
1838
1834
|
it("should find child by name", () => {
|
|
1839
|
-
const root =
|
|
1835
|
+
const root = JQLite("<div><div>text</div></div>");
|
|
1840
1836
|
const innerDiv = root.find("div");
|
|
1841
1837
|
expect(innerDiv.length).toEqual(1);
|
|
1842
1838
|
expect(innerDiv.html()).toEqual("text");
|
|
1843
1839
|
});
|
|
1844
1840
|
|
|
1845
1841
|
it("should find child by name and not care about text nodes", () => {
|
|
1846
|
-
const divs =
|
|
1842
|
+
const divs = JQLite(
|
|
1847
1843
|
"<div><span>aa</span></div>text<div><span>bb</span></div>",
|
|
1848
1844
|
);
|
|
1849
1845
|
const innerSpan = divs.find("span");
|
|
@@ -1853,7 +1849,7 @@ describe("jqLite", () => {
|
|
|
1853
1849
|
|
|
1854
1850
|
describe("eq", () => {
|
|
1855
1851
|
it("should select the nth element ", () => {
|
|
1856
|
-
const element =
|
|
1852
|
+
const element = JQLite(
|
|
1857
1853
|
"<div><span>aa</span></div><div><span>bb</span></div>",
|
|
1858
1854
|
);
|
|
1859
1855
|
expect(element.find("span").eq(0).html()).toBe("aa");
|
|
@@ -1864,7 +1860,7 @@ describe("jqLite", () => {
|
|
|
1864
1860
|
|
|
1865
1861
|
describe("triggerHandler", () => {
|
|
1866
1862
|
it("should trigger all registered handlers for an event", () => {
|
|
1867
|
-
const element =
|
|
1863
|
+
const element = JQLite("<span>poke</span>");
|
|
1868
1864
|
const pokeSpy = jasmine.createSpy("poke");
|
|
1869
1865
|
const clickSpy1 = jasmine.createSpy("clickSpy1");
|
|
1870
1866
|
const clickSpy2 = jasmine.createSpy("clickSpy2");
|
|
@@ -1891,7 +1887,7 @@ describe("jqLite", () => {
|
|
|
1891
1887
|
// we need the event to have at least preventDefault because AngularJS will call it on
|
|
1892
1888
|
// all anchors with no href automatically
|
|
1893
1889
|
|
|
1894
|
-
const element =
|
|
1890
|
+
const element = JQLite("<a>poke</a>");
|
|
1895
1891
|
const pokeSpy = jasmine.createSpy("poke");
|
|
1896
1892
|
let event;
|
|
1897
1893
|
|
|
@@ -1905,7 +1901,7 @@ describe("jqLite", () => {
|
|
|
1905
1901
|
});
|
|
1906
1902
|
|
|
1907
1903
|
it("should pass extra parameters as an additional argument", () => {
|
|
1908
|
-
const element =
|
|
1904
|
+
const element = JQLite("<a>poke</a>");
|
|
1909
1905
|
const pokeSpy = jasmine.createSpy("poke");
|
|
1910
1906
|
let data;
|
|
1911
1907
|
|
|
@@ -1917,7 +1913,7 @@ describe("jqLite", () => {
|
|
|
1917
1913
|
});
|
|
1918
1914
|
|
|
1919
1915
|
it("should mark event as prevented if preventDefault is called", () => {
|
|
1920
|
-
const element =
|
|
1916
|
+
const element = JQLite("<a>poke</a>");
|
|
1921
1917
|
const pokeSpy = jasmine.createSpy("poke");
|
|
1922
1918
|
let event;
|
|
1923
1919
|
|
|
@@ -1931,7 +1927,7 @@ describe("jqLite", () => {
|
|
|
1931
1927
|
});
|
|
1932
1928
|
|
|
1933
1929
|
it("should support handlers that deregister themselves", () => {
|
|
1934
|
-
const element =
|
|
1930
|
+
const element = JQLite("<a>poke</a>");
|
|
1935
1931
|
const clickSpy = jasmine.createSpy("click");
|
|
1936
1932
|
const clickOnceSpy = jasmine.createSpy("clickOnce").and.callFake(() => {
|
|
1937
1933
|
element.off("click", clickOnceSpy);
|
|
@@ -1950,7 +1946,7 @@ describe("jqLite", () => {
|
|
|
1950
1946
|
});
|
|
1951
1947
|
|
|
1952
1948
|
it("should accept a custom event instead of eventName", () => {
|
|
1953
|
-
const element =
|
|
1949
|
+
const element = JQLite("<a>poke</a>");
|
|
1954
1950
|
const pokeSpy = jasmine.createSpy("poke");
|
|
1955
1951
|
const customEvent = {
|
|
1956
1952
|
type: "click",
|
|
@@ -1968,7 +1964,7 @@ describe("jqLite", () => {
|
|
|
1968
1964
|
});
|
|
1969
1965
|
|
|
1970
1966
|
it("should stop triggering handlers when stopImmediatePropagation is called", () => {
|
|
1971
|
-
const element =
|
|
1967
|
+
const element = JQLite(a);
|
|
1972
1968
|
const clickSpy1 = jasmine.createSpy("clickSpy1");
|
|
1973
1969
|
const clickSpy2 = jasmine.createSpy("clickSpy2").and.callFake((event) => {
|
|
1974
1970
|
event.stopImmediatePropagation();
|
|
@@ -1987,7 +1983,7 @@ describe("jqLite", () => {
|
|
|
1987
1983
|
});
|
|
1988
1984
|
|
|
1989
1985
|
it("should have event.isImmediatePropagationStopped method", () => {
|
|
1990
|
-
const element =
|
|
1986
|
+
const element = JQLite(a);
|
|
1991
1987
|
const clickSpy = jasmine.createSpy("clickSpy");
|
|
1992
1988
|
let event;
|
|
1993
1989
|
|