diff options
author | Vladislav Zarakovsky <vlad.zar@gmail.com> | 2015-12-28 09:31:07 +0300 |
---|---|---|
committer | Vladislav Zarakovsky <vlad.zar@gmail.com> | 2015-12-28 09:31:07 +0300 |
commit | 0b38bb595b9a4b8a6353fd4748dfb3c6530b57ac (patch) | |
tree | eaea8096b6ffa7f04fb218f5e9fea7942edfb668 /test/helpers/bindSpec.js | |
parent | 730f82a2bbe7aa3ac65f574e3ce1c481fd953f66 (diff) | |
parent | 5dbfd450fb5d5ce0c1b8886baed047f91d926691 (diff) | |
download | awesomplete-0b38bb595b9a4b8a6353fd4748dfb3c6530b57ac.zip awesomplete-0b38bb595b9a4b8a6353fd4748dfb3c6530b57ac.tar.gz awesomplete-0b38bb595b9a4b8a6353fd4748dfb3c6530b57ac.tar.bz2 |
Merge remote-tracking branch 'upstream/gh-pages' into features/code-climate
Diffstat (limited to 'test/helpers/bindSpec.js')
-rw-r--r-- | test/helpers/bindSpec.js | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/test/helpers/bindSpec.js b/test/helpers/bindSpec.js new file mode 100644 index 0000000..8eea7ff --- /dev/null +++ b/test/helpers/bindSpec.js @@ -0,0 +1,59 @@ +describe("Awesomplete.$.bind", function () { + + $.fixture("plain"); + + subject(function () { + return function () { Awesomplete.$.bind(this.element, this.events) }; + }); + + describe("whith invalid element", function () { + it("does nothing if element is undefined", function () { + this.element = undefined; + expect(this.subject).not.toThrow(); + }); + + it("does nothing if element is null", function () { + this.element = null; + expect(this.subject).not.toThrow(); + }); + + it("does nothing if element is false", function () { + this.element = false; + expect(this.subject).not.toThrow(); + }); + + it("does nothing if element is 0", function () { + this.element = 0; + expect(this.subject).not.toThrow(); + }); + + it("does nothing if element is empty string", function () { + this.element = ""; + expect(this.subject).not.toThrow(); + }); + }); + + describe("with valid element", function () { + def("element", function () { return $("#plain") }); + + beforeEach(function () { + spyOn(this.element, "addEventListener"); + }); + + it("adds event listeners for all events", function () { + this.events = { click: $.noop, input: $.noop }; + this.subject(); + + expect(this.element.addEventListener).toHaveBeenCalledWith("click", this.events.click); + expect(this.element.addEventListener).toHaveBeenCalledWith("input", this.events.input); + }); + + it("adds single event listener for multiple events", function () { + this.events = { "click input": $.noop }; + this.subject(); + + expect(this.element.addEventListener).toHaveBeenCalledWith("click", this.events["click input"]); + expect(this.element.addEventListener).toHaveBeenCalledWith("input", this.events["click input"]); + }); + }); +}); |