diff --git a/test/unit/events-elements.html b/test/unit/events-elements.html index 5f283af271..668c9bb934 100644 --- a/test/unit/events-elements.html +++ b/test/unit/events-elements.html @@ -93,3 +93,19 @@ }); + + + + diff --git a/test/unit/events.html b/test/unit/events.html index 518d4b97ad..1f8de1d02c 100644 --- a/test/unit/events.html +++ b/test/unit/events.html @@ -141,6 +141,36 @@ assert.deepEqual(el._removed[3], {target: 'div', event: 'bar'}); }); }); + + suite('Event Listener Cache', function() { + suiteSetup(function() { + el = document.createElement('x-double'); + document.body.appendChild(el); + el.setup(); + }); + + suiteTeardown(function() { + document.body.removeChild(el); + }); + + test('Event handler fires only once', function() { + el.fire('foo'); + assert.equal(el._warned.length, 1, 'event should fire only once'); + }); + + test('listen reuses handler cache', function() { + var expected = el._recallEventHandler(el, 'foo', el, 'missing'); + el.listen(el, 'foo', 'missing'); + var actual = el._recallEventHandler(el, 'foo', el, 'missing'); + assert.equal(actual, expected, 'function was not cached'); + }); + + test('unlisten keeps handler for caching', function() { + el.teardown(); + var fn = el._recallEventHandler(el, 'foo', el, 'missing'); + assert.ok(fn, 'should be cached'); + }); + }); });