diff options
author | Lea Verou <lea@verou.me> | 2015-12-27 23:24:10 +0200 |
---|---|---|
committer | Lea Verou <lea@verou.me> | 2015-12-27 23:24:10 +0200 |
commit | 9af4a6ef0b18901f893b116003271e4b718903f9 (patch) | |
tree | d727f656ad843bc67a3b0de83085d4862ad2dd0a /test/helpers/fireSpec.js | |
parent | 2dae7fd9d23752abff4f230c060b4d625bb77031 (diff) | |
parent | f9d6cca542c66aef3c550e65cef3940393dab88e (diff) | |
download | awesomplete-9af4a6ef0b18901f893b116003271e4b718903f9.zip awesomplete-9af4a6ef0b18901f893b116003271e4b718903f9.tar.gz awesomplete-9af4a6ef0b18901f893b116003271e4b718903f9.tar.bz2 |
Merge pull request #16785 from vlazar/features/improve-test-coverage
Improve test coverage
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)); + }); + }); +}); |