Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dfreedm committed Oct 6, 2015
1 parent 8bd380a commit 900d82b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/unit/events-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,19 @@
});
</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>
30 changes: 30 additions & 0 deletions test/unit/events.html
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
</script>

Expand Down

0 comments on commit 900d82b

Please sign in to comment.