diff options
-rw-r--r-- | awesomplete.js | 4 | ||||
-rw-r--r-- | test/api/closeSpec.js | 8 |
2 files changed, 12 insertions, 0 deletions
diff --git a/awesomplete.js b/awesomplete.js index 7303652..627f195 100644 --- a/awesomplete.js +++ b/awesomplete.js @@ -147,6 +147,10 @@ _.prototype = { }, close: function () { + if (!this.opened) { + return; + } + this.ul.setAttribute("hidden", ""); this.index = -1; diff --git a/test/api/closeSpec.js b/test/api/closeSpec.js index e22fe2f..65228ff 100644 --- a/test/api/closeSpec.js +++ b/test/api/closeSpec.js @@ -26,4 +26,12 @@ describe("awesomplete.close", function () { expect(handler).toHaveBeenCalled(); }); + + it("returns early if already closed", function () { + var handler = $.spyOnEvent(this.subject.input, "awesomplete-close"); + this.subject.close(); + this.subject.close(); + + expect(handler.calls.count()).toBe(1); + }); }); |