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/fireSpec.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/fireSpec.js')
-rw-r--r-- | test/helpers/fireSpec.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/helpers/fireSpec.js b/test/helpers/fireSpec.js new file mode 100644 index 0000000..f876cce --- /dev/null +++ b/test/helpers/fireSpec.js @@ -0,0 +1,60 @@ +describe("Awesomplete.$.fire", function () { + + $.fixture("plain"); + + subject(function () { + return Awesomplete.$.fire.bind(Awesomplete.$, this.element); + }); + + def("element", function () { return $("#plain") }); + + beforeEach(function () { + spyOn(this.element, "dispatchEvent"); + }); + + it("fires event once", function () { + this.subject("click"); + expect(this.element.dispatchEvent.calls.count()).toEqual(1); + }); + + describe("fires different event types", function () { + it("fires click event", function () { + this.subject("click"); + expect(this.element.dispatchEvent).toHaveBeenCalledWith(jasmine.objectContaining({ type: "click" })); + }); + + it("fires input event", function () { + this.subject("input"); + expect(this.element.dispatchEvent).toHaveBeenCalledWith(jasmine.objectContaining({ type: "input" })); + }); + }); + + describe("sets event properties", function () { + it("makes cancelable event", function () { + this.subject("click"); + expect(this.element.dispatchEvent).toHaveBeenCalledWith(jasmine.objectContaining({ cancelable: true })); + }); + + it("can't make non cancelable event", function () { + this.subject("click", { cancelable: false }); + expect(this.element.dispatchEvent).toHaveBeenCalledWith(jasmine.objectContaining({ cancelable: true })); + }); + + it("makes event that bubbles", function () { + this.subject("click"); + expect(this.element.dispatchEvent).toHaveBeenCalledWith(jasmine.objectContaining({ bubbles: true })); + }); + + it("can't make event that does not bubble", function () { + this.subject("click", { bubles: false }); + expect(this.element.dispatchEvent).toHaveBeenCalledWith(jasmine.objectContaining({ bubbles: true })); + }); + + it("sets properties on the event", function () { + var properties = { text: "hello", preventDefault: $.noop }; + + this.subject("click", properties); + expect(this.element.dispatchEvent).toHaveBeenCalledWith(jasmine.objectContaining(properties)); + }); + }); +}); |