MCPcopy
hub / github.com/LeaVerou/awesomplete / itSelects

Function itSelects

test/api/selectSpec.js:42–110  ·  view source on GitHub ↗
(expectedTxt)

Source from the content-addressed store, hash-verified

40 // Shared behaviors
41
42 function itSelects(expectedTxt) {
43 it("fires awesomplete-select event", function () {
44 var handler = $.spyOnEvent(this.subject.input, "awesomplete-select");
45 this.subject.select(this.selectArgument);
46
47 expect(handler).toHaveBeenCalledWith(
48 jasmine.objectContaining({
49 text: jasmine.objectContaining({ label: expectedTxt, value: expectedTxt }),
50 origin: this.selectArgument || this.subject.ul.children[0]
51 })
52 );
53 });
54
55 describe("and awesomplete-select event was not prevented", function () {
56 beforeEach(function () {
57 $.on(this.subject.input, "awesomplete-select", $.noop);
58 });
59
60 it("changes the input value", function () {
61 this.subject.select(this.selectArgument);
62 expect(this.subject.input.value).toBe(expectedTxt);
63 });
64
65 it("closes completer", function () {
66 spyOn(this.subject, "close");
67 this.subject.select(this.selectArgument);
68
69 expect(this.subject.close).toHaveBeenCalledWith({
70 reason: "select"
71 });
72 });
73
74 it("fires awesomplete-selectcomplete event", function () {
75 var handler = $.spyOnEvent(this.subject.input, "awesomplete-selectcomplete");
76 this.subject.select(this.selectArgument);
77
78 expect(handler).toHaveBeenCalledWith(
79 jasmine.objectContaining({
80 text: jasmine.objectContaining({ label: expectedTxt, value: expectedTxt })
81 })
82 );
83 });
84 });
85
86 describe("and awesomplete-select event was prevented", function () {
87 beforeEach(function () {
88 $.on(this.subject.input, "awesomplete-select", function (evt) { evt.preventDefault() });
89 });
90
91 it("does not change the input value", function () {
92 this.subject.select(this.selectArgument);
93 expect(this.subject.input.value).toBe("ite");
94 });
95
96 it("does not close completer", function () {
97 spyOn(this.subject, "close");
98 this.subject.select(this.selectArgument);
99

Callers 1

selectSpec.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected