2016-08-04 17:49:32 +02:00
|
|
|
/* eslint-env qunit */
|
2015-05-04 01:12:38 +02:00
|
|
|
import * as Events from '../../src/js/utils/events.js';
|
2015-03-26 06:43:41 +02:00
|
|
|
import document from 'global/document';
|
2016-12-05 23:22:49 +02:00
|
|
|
import log from '../../src/js/utils/log.js';
|
2013-01-11 00:06:12 +03:00
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
QUnit.module('Events');
|
2015-03-11 03:01:11 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should add and remove an event listener to an element', function(assert) {
|
|
|
|
assert.expect(1);
|
2013-01-11 00:06:12 +03:00
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
const el = document.createElement('div');
|
|
|
|
const listener = function() {
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(true, 'Click Triggered');
|
2013-01-11 00:06:12 +03:00
|
|
|
};
|
|
|
|
|
2015-03-11 03:01:11 +02:00
|
|
|
Events.on(el, 'click', listener);
|
2016-08-04 17:49:32 +02:00
|
|
|
// 1 click
|
|
|
|
Events.trigger(el, 'click');
|
2015-03-11 03:01:11 +02:00
|
|
|
Events.off(el, 'click', listener);
|
2016-08-04 17:49:32 +02:00
|
|
|
// No click should happen.
|
|
|
|
Events.trigger(el, 'click');
|
2013-01-11 00:06:12 +03:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should add and remove multiple event listeners to an element with a single call', function(assert) {
|
|
|
|
assert.expect(6);
|
2014-07-08 21:51:47 +03:00
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
const el = document.createElement('div');
|
|
|
|
const listener = function() {
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(true, 'Callback triggered');
|
2014-07-08 21:51:47 +03:00
|
|
|
};
|
|
|
|
|
2015-03-11 03:01:11 +02:00
|
|
|
Events.on(el, ['click', 'event1', 'event2'], listener);
|
2014-07-08 21:51:47 +03:00
|
|
|
|
2015-03-11 03:01:11 +02:00
|
|
|
Events.trigger(el, 'click');
|
|
|
|
Events.trigger(el, 'click');
|
|
|
|
Events.off(el, 'click', listener);
|
2016-08-04 17:49:32 +02:00
|
|
|
// No click should happen.
|
|
|
|
Events.trigger(el, 'click');
|
2014-07-08 21:51:47 +03:00
|
|
|
|
2015-03-11 03:01:11 +02:00
|
|
|
Events.trigger(el, 'event1');
|
|
|
|
Events.trigger(el, 'event1');
|
|
|
|
Events.off(el, 'event1', listener);
|
2016-08-04 17:49:32 +02:00
|
|
|
// No event1 should happen.
|
|
|
|
Events.trigger(el, 'event1');
|
2014-07-08 21:51:47 +03:00
|
|
|
|
2015-03-11 03:01:11 +02:00
|
|
|
Events.trigger(el, 'event2');
|
|
|
|
Events.trigger(el, 'event2');
|
|
|
|
Events.off(el, 'event2', listener);
|
2016-08-04 17:49:32 +02:00
|
|
|
// No event2 should happen.
|
|
|
|
Events.trigger(el, 'event2');
|
2019-03-18 21:49:48 +02:00
|
|
|
|
|
|
|
Events.off(el, ['click', 'event1', 'event2'], listener);
|
2014-07-08 21:51:47 +03:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should be possible to pass data when you trigger an event', function(assert) {
|
|
|
|
assert.expect(6);
|
2016-08-04 17:49:32 +02:00
|
|
|
const el = document.createElement('div');
|
|
|
|
const fakeData1 = 'Fake Data 1';
|
|
|
|
const fakeData2 = {txt: 'Fake Data 2'};
|
2015-06-05 19:36:59 +02:00
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
const listener = function(evt, hash) {
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(true, 'Callback triggered');
|
|
|
|
assert.deepEqual(fakeData1, hash.d1, 'Shoulbe be passed to the handler');
|
|
|
|
assert.deepEqual(fakeData2, hash.d2, 'Shoulbe be passed to the handler');
|
2015-06-05 19:36:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
Events.on(el, ['event1', 'event2'], listener);
|
2016-08-04 17:49:32 +02:00
|
|
|
Events.trigger(el, 'event1', { d1: fakeData1, d2: fakeData2});
|
|
|
|
Events.trigger(el, 'event2', { d1: fakeData1, d2: fakeData2});
|
2015-06-05 19:36:59 +02:00
|
|
|
|
2019-03-18 21:49:48 +02:00
|
|
|
Events.off(el, ['event1', 'event2'], listener);
|
2015-06-05 19:36:59 +02:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should remove all listeners of a type', function(assert) {
|
2016-08-04 17:49:32 +02:00
|
|
|
const el = document.createElement('div');
|
|
|
|
let clicks = 0;
|
|
|
|
const listener = function() {
|
2013-01-11 00:06:12 +03:00
|
|
|
clicks++;
|
|
|
|
};
|
2016-08-04 17:49:32 +02:00
|
|
|
const listener2 = function() {
|
2013-01-11 00:06:12 +03:00
|
|
|
clicks++;
|
|
|
|
};
|
|
|
|
|
2015-03-11 03:01:11 +02:00
|
|
|
Events.on(el, 'click', listener);
|
|
|
|
Events.on(el, 'click', listener2);
|
2018-09-28 20:58:15 +02:00
|
|
|
// 2 clicks
|
2016-08-04 17:49:32 +02:00
|
|
|
Events.trigger(el, 'click');
|
2013-01-11 00:06:12 +03:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(clicks === 2, 'both click listeners fired');
|
2013-01-11 00:06:12 +03:00
|
|
|
|
2015-03-11 03:01:11 +02:00
|
|
|
Events.off(el, 'click');
|
2016-08-04 17:49:32 +02:00
|
|
|
// No click should happen.
|
|
|
|
Events.trigger(el, 'click');
|
2013-01-11 00:06:12 +03:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(clicks === 2, 'no click listeners fired');
|
2013-01-11 00:06:12 +03:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should remove all listeners of an array of types', function(assert) {
|
2016-08-04 17:49:32 +02:00
|
|
|
const el = document.createElement('div');
|
|
|
|
let calls = 0;
|
|
|
|
const listener = function() {
|
2014-07-08 21:51:47 +03:00
|
|
|
calls++;
|
|
|
|
};
|
2016-08-04 17:49:32 +02:00
|
|
|
const listener2 = function() {
|
2014-07-08 21:51:47 +03:00
|
|
|
calls++;
|
|
|
|
};
|
|
|
|
|
2015-03-11 03:01:11 +02:00
|
|
|
Events.on(el, ['click', 'event1'], listener);
|
|
|
|
Events.on(el, ['click', 'event1'], listener2);
|
2016-08-04 17:49:32 +02:00
|
|
|
// 2 calls
|
|
|
|
Events.trigger(el, 'click');
|
|
|
|
// 2 calls
|
|
|
|
Events.trigger(el, 'event1');
|
2014-07-08 21:51:47 +03:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(calls === 4, 'both click listeners fired');
|
2014-07-08 21:51:47 +03:00
|
|
|
|
2015-03-11 03:01:11 +02:00
|
|
|
Events.off(el, ['click', 'event1']);
|
2016-08-04 17:49:32 +02:00
|
|
|
// No click should happen.
|
|
|
|
Events.trigger(el, 'click');
|
|
|
|
// No event1 should happen.
|
|
|
|
Events.trigger(el, 'event1');
|
2014-07-08 21:51:47 +03:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(calls === 4, 'no event listeners fired');
|
2014-07-08 21:51:47 +03:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should remove all listeners from an element', function(assert) {
|
|
|
|
assert.expect(2);
|
2013-01-11 00:06:12 +03:00
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
const el = document.createElement('div');
|
|
|
|
const listener = function() {
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(true, 'Fake1 Triggered');
|
2013-01-11 00:06:12 +03:00
|
|
|
};
|
2016-08-04 17:49:32 +02:00
|
|
|
const listener2 = function() {
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(true, 'Fake2 Triggered');
|
2013-01-11 00:06:12 +03:00
|
|
|
};
|
|
|
|
|
2015-03-11 03:01:11 +02:00
|
|
|
Events.on(el, 'fake1', listener);
|
|
|
|
Events.on(el, 'fake2', listener2);
|
2013-01-11 00:06:12 +03:00
|
|
|
|
2015-03-11 03:01:11 +02:00
|
|
|
Events.trigger(el, 'fake1');
|
|
|
|
Events.trigger(el, 'fake2');
|
2013-01-11 00:06:12 +03:00
|
|
|
|
2015-03-11 03:01:11 +02:00
|
|
|
Events.off(el);
|
2013-01-11 00:06:12 +03:00
|
|
|
|
|
|
|
// No listener should happen.
|
2015-03-11 03:01:11 +02:00
|
|
|
Events.trigger(el, 'fake1');
|
|
|
|
Events.trigger(el, 'fake2');
|
2019-03-18 21:49:48 +02:00
|
|
|
|
|
|
|
Events.off(el, 'fake1', listener);
|
|
|
|
Events.off(el, 'fake2', listener2);
|
2013-01-11 00:06:12 +03:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should listen only once', function(assert) {
|
|
|
|
assert.expect(1);
|
2013-01-11 00:06:12 +03:00
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
const el = document.createElement('div');
|
|
|
|
const listener = function() {
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(true, 'Click Triggered');
|
2013-01-11 00:06:12 +03:00
|
|
|
};
|
|
|
|
|
2015-03-11 03:01:11 +02:00
|
|
|
Events.one(el, 'click', listener);
|
2016-08-04 17:49:32 +02:00
|
|
|
// 1 click
|
|
|
|
Events.trigger(el, 'click');
|
|
|
|
// No click should happen.
|
|
|
|
Events.trigger(el, 'click');
|
2013-01-11 00:06:12 +03:00
|
|
|
});
|
2013-01-18 04:33:53 +03:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should listen only once in multiple events from a single call', function(assert) {
|
|
|
|
assert.expect(3);
|
2014-07-08 21:51:47 +03:00
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
const el = document.createElement('div');
|
|
|
|
const listener = function() {
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(true, 'Callback Triggered');
|
2014-07-08 21:51:47 +03:00
|
|
|
};
|
|
|
|
|
2015-03-11 03:01:11 +02:00
|
|
|
Events.one(el, ['click', 'event1', 'event2'], listener);
|
2016-08-04 17:49:32 +02:00
|
|
|
// 1 click
|
|
|
|
Events.trigger(el, 'click');
|
|
|
|
// No click should happen.
|
|
|
|
Events.trigger(el, 'click');
|
|
|
|
// event1 must be handled.
|
|
|
|
Events.trigger(el, 'event1');
|
|
|
|
// No event1 should be handled.
|
|
|
|
Events.trigger(el, 'event1');
|
|
|
|
// event2 must be handled.
|
|
|
|
Events.trigger(el, 'event2');
|
|
|
|
// No event2 should be handled.
|
|
|
|
Events.trigger(el, 'event2');
|
2014-07-08 21:51:47 +03:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should stop immediate propagtion', function(assert) {
|
|
|
|
assert.expect(1);
|
2013-01-18 04:33:53 +03:00
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
const el = document.createElement('div');
|
2013-01-18 04:33:53 +03:00
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
Events.on(el, 'test', function(e) {
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(true, 'First listener fired');
|
2013-01-18 04:33:53 +03:00
|
|
|
e.stopImmediatePropagation();
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
Events.on(el, 'test', function(e) {
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(false, 'Second listener fired');
|
2013-01-18 04:33:53 +03:00
|
|
|
});
|
|
|
|
|
2015-03-11 03:01:11 +02:00
|
|
|
Events.trigger(el, 'test');
|
2019-03-18 21:49:48 +02:00
|
|
|
Events.off(el, 'test');
|
2013-01-18 04:33:53 +03:00
|
|
|
});
|
2013-09-04 23:33:27 +03:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should bubble up DOM unless bubbles == false', function(assert) {
|
|
|
|
assert.expect(3);
|
2013-09-04 23:33:27 +03:00
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
const outer = document.createElement('div');
|
|
|
|
const inner = outer.appendChild(document.createElement('div'));
|
2013-09-04 23:33:27 +03:00
|
|
|
|
|
|
|
// Verify that if bubbles === true, event bubbles up dom.
|
2016-08-04 17:49:32 +02:00
|
|
|
Events.on(inner, 'bubbles', function(e) {
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(true, 'Inner listener fired');
|
2013-09-04 23:33:27 +03:00
|
|
|
});
|
2016-08-04 17:49:32 +02:00
|
|
|
Events.on(outer, 'bubbles', function(e) {
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(true, 'Outer listener fired');
|
2013-09-04 23:33:27 +03:00
|
|
|
});
|
2016-08-04 17:49:32 +02:00
|
|
|
Events.trigger(inner, { type: 'bubbles', target: inner, bubbles: true });
|
2013-09-04 23:33:27 +03:00
|
|
|
|
|
|
|
// Only change 'bubbles' to false, and verify only inner handler is called.
|
2016-08-04 17:49:32 +02:00
|
|
|
Events.on(inner, 'nobub', function(e) {
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(true, 'Inner listener fired');
|
2013-09-04 23:33:27 +03:00
|
|
|
});
|
2016-08-04 17:49:32 +02:00
|
|
|
Events.on(outer, 'nobub', function(e) {
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(false, 'Outer listener fired');
|
2013-09-04 23:33:27 +03:00
|
|
|
});
|
2016-08-04 17:49:32 +02:00
|
|
|
Events.trigger(inner, { type: 'nobub', target: inner, bubbles: false });
|
2019-03-18 21:49:48 +02:00
|
|
|
|
|
|
|
Events.off(inner, 'bubbles');
|
|
|
|
Events.off(outer, 'bubbles');
|
|
|
|
Events.off(inner, 'nobub');
|
|
|
|
Events.off(outer, 'nobub');
|
2013-09-04 23:33:27 +03:00
|
|
|
});
|
2014-03-25 00:56:02 +03:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should have a defaultPrevented property on an event that was prevent from doing default action', function(assert) {
|
|
|
|
assert.expect(2);
|
2014-03-25 00:56:02 +03:00
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
const el = document.createElement('div');
|
2014-03-25 00:56:02 +03:00
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
Events.on(el, 'test', function(e) {
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(true, 'First listener fired');
|
2014-03-25 00:56:02 +03:00
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
Events.on(el, 'test', function(e) {
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(e.defaultPrevented, 'Should have `defaultPrevented` to signify preventDefault being called');
|
2014-03-25 00:56:02 +03:00
|
|
|
});
|
|
|
|
|
2015-03-11 03:01:11 +02:00
|
|
|
Events.trigger(el, 'test');
|
2019-03-18 21:49:48 +02:00
|
|
|
Events.off(el, 'test');
|
2014-03-25 00:56:02 +03:00
|
|
|
});
|
2015-04-09 12:03:29 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should have relatedTarget correctly set on the event', function(assert) {
|
|
|
|
assert.expect(2);
|
2015-04-09 12:03:29 +02:00
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
const el1 = document.createElement('div');
|
|
|
|
const el2 = document.createElement('div');
|
|
|
|
const relatedEl = document.createElement('div');
|
2015-04-09 12:03:29 +02:00
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
Events.on(el1, 'click', function(e) {
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(e.relatedTarget, relatedEl, 'relatedTarget is set for all browsers when related element is set on the event');
|
2015-04-09 12:03:29 +02:00
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
Events.trigger(el1, { type: 'click', relatedTarget: relatedEl });
|
2015-04-09 12:03:29 +02:00
|
|
|
|
|
|
|
Events.on(el2, 'click', function(e) {
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(e.relatedTarget, null, 'relatedTarget is null when none is provided');
|
2015-04-09 12:03:29 +02:00
|
|
|
});
|
|
|
|
|
2016-08-04 17:49:32 +02:00
|
|
|
Events.trigger(el2, { type: 'click', relatedTarget: undefined });
|
2019-03-18 21:49:48 +02:00
|
|
|
|
|
|
|
Events.off(el1, 'click');
|
|
|
|
Events.off(el2, 'click');
|
2015-04-09 12:03:29 +02:00
|
|
|
});
|
2016-08-26 01:08:56 +02:00
|
|
|
|
|
|
|
QUnit.test('should execute remaining handlers after an exception in an event handler', function(assert) {
|
|
|
|
assert.expect(1);
|
|
|
|
|
2016-12-05 23:22:49 +02:00
|
|
|
const oldLogError = log.error;
|
|
|
|
|
|
|
|
log.error = function() {};
|
|
|
|
|
2016-08-26 01:08:56 +02:00
|
|
|
const el = document.createElement('div');
|
|
|
|
const listener1 = function() {
|
|
|
|
throw new Error('GURU MEDITATION ERROR');
|
|
|
|
};
|
|
|
|
const listener2 = function() {
|
|
|
|
assert.ok(true, 'Click Triggered');
|
|
|
|
};
|
|
|
|
|
|
|
|
Events.on(el, 'click', listener1);
|
|
|
|
Events.on(el, 'click', listener2);
|
|
|
|
|
|
|
|
// 1 click
|
|
|
|
Events.trigger(el, 'click');
|
2016-12-05 23:22:49 +02:00
|
|
|
|
|
|
|
log.error = oldLogError;
|
2019-03-18 21:49:48 +02:00
|
|
|
|
|
|
|
Events.off(el, 'click');
|
2016-08-26 01:08:56 +02:00
|
|
|
});
|
2018-03-05 23:42:06 +02:00
|
|
|
|
|
|
|
QUnit.test('trigger with an object should set the correct target property', function(assert) {
|
|
|
|
const el = document.createElement('div');
|
|
|
|
|
|
|
|
Events.on(el, 'click', function(e) {
|
|
|
|
assert.equal(e.target, el, 'the event object target should be our element');
|
|
|
|
});
|
|
|
|
Events.trigger(el, { type: 'click'});
|
2019-03-18 21:49:48 +02:00
|
|
|
|
|
|
|
Events.off(el, 'click');
|
2018-03-05 23:42:06 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test('retrigger with a string should use the new element as target', function(assert) {
|
|
|
|
const el1 = document.createElement('div');
|
|
|
|
const el2 = document.createElement('div');
|
|
|
|
|
|
|
|
Events.on(el2, 'click', function(e) {
|
|
|
|
assert.equal(e.target, el2, 'the event object target should be the new element');
|
|
|
|
});
|
|
|
|
Events.on(el1, 'click', function(e) {
|
|
|
|
Events.trigger(el2, 'click');
|
|
|
|
});
|
|
|
|
Events.trigger(el1, 'click');
|
|
|
|
Events.trigger(el1, {type: 'click'});
|
2019-03-18 21:49:48 +02:00
|
|
|
|
|
|
|
Events.off(el1, 'click');
|
|
|
|
Events.off(el2, 'click');
|
2018-03-05 23:42:06 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test('retrigger with an object should use the old element as target', function(assert) {
|
|
|
|
const el1 = document.createElement('div');
|
|
|
|
const el2 = document.createElement('div');
|
|
|
|
|
|
|
|
Events.on(el2, 'click', function(e) {
|
|
|
|
assert.equal(e.target, el1, 'the event object target should be the old element');
|
|
|
|
});
|
|
|
|
Events.on(el1, 'click', function(e) {
|
|
|
|
Events.trigger(el2, e);
|
|
|
|
});
|
|
|
|
Events.trigger(el1, 'click');
|
|
|
|
Events.trigger(el1, {type: 'click'});
|
2019-03-18 21:49:48 +02:00
|
|
|
|
|
|
|
Events.off(el1, 'click');
|
|
|
|
Events.off(el2, 'click');
|
2018-03-05 23:42:06 +02:00
|
|
|
});
|
2019-06-17 20:04:25 +02:00
|
|
|
|
|
|
|
QUnit.test('should listen only once for any', function(assert) {
|
|
|
|
const el = document.createElement('div');
|
|
|
|
let triggered = 0;
|
|
|
|
const listener = () => triggered++;
|
|
|
|
|
|
|
|
Events.any(el, 'click', listener);
|
|
|
|
assert.equal(triggered, 0, 'listener was not yet triggered');
|
|
|
|
// 1 click
|
|
|
|
Events.trigger(el, 'click');
|
|
|
|
|
|
|
|
assert.equal(triggered, 1, 'listener was triggered');
|
|
|
|
// No click should happen.
|
|
|
|
Events.trigger(el, 'click');
|
|
|
|
assert.equal(triggered, 1, 'listener was not triggered again');
|
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test('only the first event should call listener via any', function(assert) {
|
|
|
|
const el = document.createElement('div');
|
|
|
|
let triggered = 0;
|
|
|
|
const listener = () => triggered++;
|
|
|
|
|
|
|
|
Events.any(el, ['click', 'event1', 'event2'], listener);
|
|
|
|
assert.equal(triggered, 0, 'listener was not yet triggered');
|
|
|
|
|
|
|
|
// 1 click
|
|
|
|
Events.trigger(el, 'click');
|
|
|
|
assert.equal(triggered, 1, 'listener was triggered');
|
|
|
|
// nothing below here should trigger the Callback
|
|
|
|
Events.trigger(el, 'click');
|
|
|
|
Events.trigger(el, 'event1');
|
|
|
|
Events.trigger(el, 'event1');
|
|
|
|
Events.trigger(el, 'event2');
|
|
|
|
Events.trigger(el, 'event2');
|
|
|
|
assert.equal(triggered, 1, 'listener was not triggered again');
|
|
|
|
});
|