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
|
describe("Awesomplete.$", function () {
$.fixture("options");
subject(function () { return Awesomplete.$(this.expression, this.context) });
describe("with default context", itFindsElement);
describe("with custom context", function () {
def("context", function () { return fixture.el });
itFindsElement();
});
describe("with truthy non string expression", function () {
it("returns the expression back", function () {
this.expression = $("#no-options");
expect(this.subject).toBe(this.expression);
});
});
describe("with falsy non string expression", function () {
it("returns null if expression is undefined", function () {
this.expression = undefined;
expect(this.subject).toBeNull();
});
it("returns null if expression is null", function () {
this.expression = null;
expect(this.subject).toBeNull();
});
it("returns null if expression is false", function () {
this.expression = false;
expect(this.subject).toBeNull();
});
});
// Shared behaviors
function itFindsElement() {
it("returns DOM element", function () {
this.expression = "#no-options";
expect(this.subject instanceof HTMLElement).toBe(true);
});
it("finds by id", function () {
this.expression = "#no-options";
expect(this.subject.id).toEqual("no-options");
});
it("finds by class name", function () {
this.expression = ".simple-input";
expect(this.subject.id).toEqual("no-options");
});
it("finds by tag name", function () {
this.expression = "datalist";
expect(this.subject.id).toEqual("list");
});
}
});
|