From a4e2cd1f494dbf720b5b547d901c2fb7d431f229 Mon Sep 17 00:00:00 2001 From: Cherif BOUCHELAGHEM Date: Fri, 19 Oct 2018 23:27:56 +0100 Subject: [PATCH 1/6] edit tests for IE --- can-dom-events-test.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/can-dom-events-test.js b/can-dom-events-test.js index 1629b09..5496c98 100644 --- a/can-dom-events-test.js +++ b/can-dom-events-test.js @@ -10,13 +10,19 @@ unit.test('domEvents.addEventListener works', function (assert) { var input = document.createElement('input'); var eventType = 'click'; + var event; + var handler = function () { assert.ok(true, 'event handler should be called'); }; - domEvents.addEventListener(input, eventType, handler); - - var event = new Event(eventType); + domEvents.addEventListener(input, eventType, handler, false); + if (typeof Event === "function") { + event = new Event(eventType); + } else { + event = document.createEvent('Event'); + event.initEvent(eventType, false, true); + } input.dispatchEvent(event); domEvents.removeEventListener(input, eventType, handler); @@ -29,18 +35,29 @@ unit.test('domEvents.removeEventListener works', function (assert) { var input = document.createElement('input'); var eventType = 'click'; + var event, event2; var handler = function () { assert.ok(true, 'event handler should be called'); }; domEvents.addEventListener(input, eventType, handler); - var event = new Event(eventType); + if (typeof Event === "function") { + event = new Event(eventType); + } else { + event = document.createEvent('Event'); + event.initEvent(eventType, true, true); + } input.dispatchEvent(event); domEvents.removeEventListener(input, eventType, handler); - var event2 = new Event(eventType); + if (typeof Event === "function") { + var event2 = new Event(eventType); + } else { + event2 = document.createEvent('Event'); + event2.initEvent(eventType, true, true); + } input.dispatchEvent(event2); }); From 9675002f40abae3959eb85e4e2ad10df820711f4 Mon Sep 17 00:00:00 2001 From: Cherif BOUCHELAGHEM Date: Fri, 19 Oct 2018 23:32:04 +0100 Subject: [PATCH 2/6] fix linting error --- can-dom-events-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can-dom-events-test.js b/can-dom-events-test.js index 5496c98..c4844ae 100644 --- a/can-dom-events-test.js +++ b/can-dom-events-test.js @@ -53,7 +53,7 @@ unit.test('domEvents.removeEventListener works', function (assert) { domEvents.removeEventListener(input, eventType, handler); if (typeof Event === "function") { - var event2 = new Event(eventType); + event2 = new Event(eventType); } else { event2 = document.createEvent('Event'); event2.initEvent(eventType, true, true); From 635f9cd90c9ca2c778c99e25de1b2671d309b204 Mon Sep 17 00:00:00 2001 From: Cherif BOUCHELAGHEM Date: Mon, 22 Oct 2018 21:12:44 +0100 Subject: [PATCH 3/6] fix tests for IE11 --- can-dom-events-test.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/can-dom-events-test.js b/can-dom-events-test.js index c4844ae..7ee0166 100644 --- a/can-dom-events-test.js +++ b/can-dom-events-test.js @@ -16,15 +16,16 @@ unit.test('domEvents.addEventListener works', function (assert) { assert.ok(true, 'event handler should be called'); }; - domEvents.addEventListener(input, eventType, handler, false); + domEvents.addEventListener(input, eventType, handler); if (typeof Event === "function") { event = new Event(eventType); } else { + var qf = document.querySelector('#qunit-fixture'); + qf.appendChild(input); event = document.createEvent('Event'); - event.initEvent(eventType, false, true); + event.initEvent(eventType, true, false); } input.dispatchEvent(event); - domEvents.removeEventListener(input, eventType, handler); }); @@ -36,6 +37,7 @@ unit.test('domEvents.removeEventListener works', function (assert) { var input = document.createElement('input'); var eventType = 'click'; var event, event2; + var qf = document.querySelector('#qunit-fixture'); var handler = function () { assert.ok(true, 'event handler should be called'); }; @@ -45,6 +47,7 @@ unit.test('domEvents.removeEventListener works', function (assert) { if (typeof Event === "function") { event = new Event(eventType); } else { + qf.appendChild(input); event = document.createEvent('Event'); event.initEvent(eventType, true, true); } @@ -55,6 +58,9 @@ unit.test('domEvents.removeEventListener works', function (assert) { if (typeof Event === "function") { event2 = new Event(eventType); } else { + if (!qf.contains(input)) { + qf.appendChild(input); + } event2 = document.createEvent('Event'); event2.initEvent(eventType, true, true); } @@ -74,6 +80,11 @@ unit.test('domEvents.dispatch works', function (assert) { input.addEventListener(eventType, handler); + if (typeof Event !== "function") { + var qf = document.querySelector('#qunit-fixture'); + qf.appendChild(input); + } + domEvents.dispatch(input, eventType); input.removeEventListener(eventType, handler); From 1181693d53910c06040989b221a8a79f64362b3f Mon Sep 17 00:00:00 2001 From: Cherif BOUCHELAGHEM Date: Mon, 22 Oct 2018 22:23:09 +0100 Subject: [PATCH 4/6] edit the test as in the review --- can-dom-events-test.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/can-dom-events-test.js b/can-dom-events-test.js index 7ee0166..0ab58b7 100644 --- a/can-dom-events-test.js +++ b/can-dom-events-test.js @@ -11,6 +11,8 @@ unit.test('domEvents.addEventListener works', function (assert) { var input = document.createElement('input'); var eventType = 'click'; var event; + var qf = document.querySelector('#qunit-fixture'); + qf.appendChild(input); var handler = function () { assert.ok(true, 'event handler should be called'); @@ -20,8 +22,6 @@ unit.test('domEvents.addEventListener works', function (assert) { if (typeof Event === "function") { event = new Event(eventType); } else { - var qf = document.querySelector('#qunit-fixture'); - qf.appendChild(input); event = document.createEvent('Event'); event.initEvent(eventType, true, false); } @@ -38,6 +38,7 @@ unit.test('domEvents.removeEventListener works', function (assert) { var eventType = 'click'; var event, event2; var qf = document.querySelector('#qunit-fixture'); + qf.appendChild(input); var handler = function () { assert.ok(true, 'event handler should be called'); }; @@ -47,7 +48,6 @@ unit.test('domEvents.removeEventListener works', function (assert) { if (typeof Event === "function") { event = new Event(eventType); } else { - qf.appendChild(input); event = document.createEvent('Event'); event.initEvent(eventType, true, true); } @@ -58,9 +58,6 @@ unit.test('domEvents.removeEventListener works', function (assert) { if (typeof Event === "function") { event2 = new Event(eventType); } else { - if (!qf.contains(input)) { - qf.appendChild(input); - } event2 = document.createEvent('Event'); event2.initEvent(eventType, true, true); } From efe19b4f9606f13e0ee7d6edef31df97c4ddc6b5 Mon Sep 17 00:00:00 2001 From: Cherif BOUCHELAGHEM Date: Mon, 22 Oct 2018 22:26:25 +0100 Subject: [PATCH 5/6] fix querySelector in one other place --- can-dom-events-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can-dom-events-test.js b/can-dom-events-test.js index 0ab58b7..ee9bd30 100644 --- a/can-dom-events-test.js +++ b/can-dom-events-test.js @@ -71,6 +71,7 @@ unit.test('domEvents.dispatch works', function (assert) { var input = document.createElement('input'); var eventType = 'click'; + var qf = document.querySelector('#qunit-fixture'); var handler = function () { assert.ok(true, 'event handler should be called'); }; @@ -78,7 +79,6 @@ unit.test('domEvents.dispatch works', function (assert) { input.addEventListener(eventType, handler); if (typeof Event !== "function") { - var qf = document.querySelector('#qunit-fixture'); qf.appendChild(input); } From 5fdd17396cea23b223bc67c4601b00f2194e9ce7 Mon Sep 17 00:00:00 2001 From: Cherif BOUCHELAGHEM Date: Mon, 22 Oct 2018 22:30:11 +0100 Subject: [PATCH 6/6] edit append input in one test --- can-dom-events-test.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/can-dom-events-test.js b/can-dom-events-test.js index ee9bd30..db55cd4 100644 --- a/can-dom-events-test.js +++ b/can-dom-events-test.js @@ -72,15 +72,13 @@ unit.test('domEvents.dispatch works', function (assert) { var input = document.createElement('input'); var eventType = 'click'; var qf = document.querySelector('#qunit-fixture'); + qf.appendChild(input); var handler = function () { assert.ok(true, 'event handler should be called'); }; input.addEventListener(eventType, handler); - if (typeof Event !== "function") { - qf.appendChild(input); - } domEvents.dispatch(input, eventType);