diff options
author | Vladislav Zarakovsky <vlad.zar@gmail.com> | 2015-11-24 12:25:39 +0300 |
---|---|---|
committer | Vladislav Zarakovsky <vlad.zar@gmail.com> | 2015-11-24 15:34:07 +0300 |
commit | e3d15e328a3941a2a4716d11a8b3236b315acc76 (patch) | |
tree | e4a80390cefef473598470c35b5e2f0b986c0f46 /test/helpers/bindSpec.js | |
parent | 2b2e3ed006671d17f6aae168e62eace66bed8481 (diff) | |
download | awesomplete-e3d15e328a3941a2a4716d11a8b3236b315acc76.zip awesomplete-e3d15e328a3941a2a4716d11a8b3236b315acc76.tar.gz awesomplete-e3d15e328a3941a2a4716d11a8b3236b315acc76.tar.bz2 |
Awesomplete.$.bind tests
Diffstat (limited to 'test/helpers/bindSpec.js')
-rw-r--r-- | test/helpers/bindSpec.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/test/helpers/bindSpec.js b/test/helpers/bindSpec.js new file mode 100644 index 0000000..09d5954 --- /dev/null +++ b/test/helpers/bindSpec.js @@ -0,0 +1,61 @@ +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"]); + }); + }); +}); |