diff options
author | Vladislav Zarakovsky <vlad.zar@gmail.com> | 2015-11-24 13:14:36 +0300 |
---|---|---|
committer | Vladislav Zarakovsky <vlad.zar@gmail.com> | 2015-11-24 15:41:02 +0300 |
commit | dcd462013daf14b7dd9629f3278f93dc4b33ad26 (patch) | |
tree | bb65063758064547098e72669275a68396e57a4d | |
parent | 4a0e723708b2f02eaa96a0d543185d47a781b1d5 (diff) | |
download | awesomplete-dcd462013daf14b7dd9629f3278f93dc4b33ad26.zip awesomplete-dcd462013daf14b7dd9629f3278f93dc4b33ad26.tar.gz awesomplete-dcd462013daf14b7dd9629f3278f93dc4b33ad26.tar.bz2 |
awesomplete.close tests
-rw-r--r-- | test/api/closeSpec.js | 33 | ||||
-rw-r--r-- | test/specHelper.js | 8 |
2 files changed, 39 insertions, 2 deletions
diff --git a/test/api/closeSpec.js b/test/api/closeSpec.js new file mode 100644 index 0000000..6661af6 --- /dev/null +++ b/test/api/closeSpec.js @@ -0,0 +1,33 @@ +describe("awesomplete.close", function () { + + $.fixture("plain"); + + subject(function () { return new Awesomplete("#plain") }); + + def("events", function () { return { closed: $.noop } }); + + beforeEach(function () { + this.subject.open(); + this.subject.next(); + }); + + it("closes completer", function () { + this.subject.close(); + expect(this.subject.ul.hasAttribute("hidden")).toBe(true); + }); + + it("makes no item selected", function () { + this.subject.close(); + + expect(this.subject.selected).toBe(false); + expect(this.subject.index).toBe(-1); + }); + + it("fires awesomplete-close event", function () { + spyOn(this.events, "closed") + $.on(this.subject.input, "awesomplete-close", this.events.closed); + + this.subject.close(); + expect(this.events.closed).toHaveBeenCalled(); + }); +}); diff --git a/test/specHelper.js b/test/specHelper.js index f00202a..2bd6fa2 100644 --- a/test/specHelper.js +++ b/test/specHelper.js @@ -5,7 +5,7 @@ function $ (str, context) { return (context || fixture.el).querySelector(str); } -function $$(str, context) { +function $$ (str, context) { return (context || fixture.el).querySelectorAll(str); } @@ -20,7 +20,11 @@ $.fixture = function (fixtureName) { afterEach(function () { fixture.cleanup(); }); -} +}; + +$.on = function (element, event, callback) { + element.addEventListener(event, callback); +}; // $.noop returns a new empty function each time it's being called Object.defineProperty($, "noop", { |