summaryrefslogtreecommitdiffstats
path: root/test/helpers/fireSpec.js
diff options
context:
space:
mode:
authorVladislav Zarakovsky <vlad.zar@gmail.com>2015-11-24 12:49:46 +0300
committerVladislav Zarakovsky <vlad.zar@gmail.com>2015-11-24 15:40:32 +0300
commit643ccfbb35f7b90607828c1b3b3b71a4f686501d (patch)
treed2228e052c74a3384a1b09f31134683127af9d39 /test/helpers/fireSpec.js
parente85128e0887e006ea7dfa28680982649cecbab83 (diff)
downloadawesomplete-643ccfbb35f7b90607828c1b3b3b71a4f686501d.zip
awesomplete-643ccfbb35f7b90607828c1b3b3b71a4f686501d.tar.gz
awesomplete-643ccfbb35f7b90607828c1b3b3b71a4f686501d.tar.bz2
Awesomplete.$.fire tests
Diffstat (limited to 'test/helpers/fireSpec.js')
-rw-r--r--test/helpers/fireSpec.js60
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));
+ });
+ });
+});