-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpr.js
80 lines (62 loc) · 2.2 KB
/
expr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
(function (modules, root, factory) {
if (typeof define === "function" && define.amd) {
define(modules, factory);
} else if (typeof module === "object" && module.exports) {
module.exports = factory.apply(root, modules.map(require));
} else {
root["mu-jquery-widget/tests/expr"] = factory.apply(root, modules.map(function (m) {
return this[m] || root[m.replace(/^\.{2}/, "mu-jquery-widget")];
}, {
"qunit": root.QUnit,
"jquery": root.jQuery
}));
}
})([
"qunit",
"jquery",
"../expr",
], this, function (QUnit, $, expr) {
var expando = $.expando;
var name = "mu-jquery-widget/expr";
QUnit.module(name);
QUnit.testStart(function(details) {
if (details.module.startsWith(name)) {
$.expr[":"].widget = expr($);
}
});
QUnit.testDone(function(details) {
if (details.skipped) {
return;
}
else if (details.module.startsWith(name)) {
delete $.expr[":"].widget;
}
});
QUnit.test("not matching selector", function (assert) {
assert.expect(1);
var $element = $("<div>");
assert.notOk($element.is(":widget"), "selector does not match");
});
QUnit.test("matching selector", function (assert) {
assert.expect(1);
var $element = $("<div>").data(expando + "#test", "test");
assert.ok($element.is(":widget"), "selector matches");
});
QUnit.test("matching search selector", function (assert) {
assert.expect(1);
var $element = $("<div>").data(expando + "#test", "test");
assert.ok($element.is(":widget(tes)"), "selector matches");
});
QUnit.test("matching selector for several $elements", function (assert) {
assert.expect(1);
var $elements = $("<div></div><div></div><div></div>");
var $element1 = $elements.eq(0).data(expando + "#test1", "test1");
var $element2 = $elements.eq(2).data(expando + "#test2", "test2");
assert.deepEqual($elements.filter(":widget").get(), [ $element1.get(0), $element2.get(0) ] , "finds matching elements");
});
QUnit.test("camelCase selector", function (assert) {
assert.expect(1);
var $element = $("<div>").data(expando + "#camel-case", "test");
assert.ok($element.is(":widget(camel-case)"), "selector matches");
});
});