mirror of
https://github.com/Polymer/polymer.git
synced 2025-02-25 18:55:30 -06:00
add tests
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user