add tests

This commit is contained in:
Daniel Freedman
2015-10-06 15:04:06 -07:00
parent 8bd380ab85
commit 900d82b42f
2 changed files with 46 additions and 0 deletions

View File

@@ -93,3 +93,19 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
});
</script>
</dom-module>
<dom-module id="x-double">
<script>
Polymer({
is: 'x-double',
behaviors: [EventLoggerImpl],
setup: function() {
this.listen(this, 'foo', 'missing');
this.listen(this, 'foo', 'missing');
},
teardown: function() {
this.unlisten(this, 'foo', 'missing');
}
});
</script>
</dom-module>

View File

@@ -141,6 +141,36 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
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');
});
});
});
</script>