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