Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Orvell committed May 12, 2017
1 parent c7a81ea commit 1f83fd7
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/unit/property-effects-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,39 @@
</script>
</dom-module>

<dom-module id="x-handle-notify-event">
<template>
<slot name="drawer"></slot>
<div id="before"></div>
<x-basic id="basic1"
on-notifyingvalue-with-default-changed="handleNotify">
</x-basic>
<div id="later"></div>
</template>
<script>
Polymer({
is: 'x-handle-notify-event',
properties: {
prop: {
observer: 'propChanged'
}
},
created: function() {
this.readySpy = sinon.spy();
this.afterSettingProp = sinon.spy();
this.propChanged = sinon.spy();
this.handleNotify = sinon.spy(function() {
this.prop = 'prop';
this.afterSettingProp();
});
},
ready: function() {
this.readySpy();
}
});
</script>
</dom-module>

<script>
Polymer({
is: 'x-reflect',
Expand Down
31 changes: 31 additions & 0 deletions test/unit/property-effects.html
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,37 @@

});

suite('handling notifying evevnts', function() {

test('handle notifcation event and set property with observer when connected', function() {
var el = document.createElement('x-handle-notify-event');
document.body.appendChild(el);
assert.ok(el.shadowRoot.querySelector('#before'), 'element not found before default notifying elmeent');
assert.ok(el.shadowRoot.querySelector('#later'), 'element not found after default notifying elmeent');
assert.isTrue(el.readySpy.calledOnce, 'ready called more than once');
assert.isTrue(el.handleNotify.calledOnce, 'listener called more than once');
assert.isTrue(el.propChanged.calledOnce, 'observer called more than once');
assert.isTrue(el.handleNotify.calledBefore(el.propChanged), 'observer called before event');
assert.isTrue(el.afterSettingProp.calledBefore(el.propChanged), 'accessor side effect processed during notifying event (before clients ready)');
assert.isTrue(el.propChanged.calledBefore(el.readySpy), 'observer called before ready');
document.body.removeChild(el);
});

test('handle notifcation event and set property with observer when *not* connected and _enableProperties called', function() {
var el = document.createElement('x-handle-notify-event');
el._enableProperties();
assert.ok(el.shadowRoot.querySelector('#before'), 'element not found before default notifying elmeent');
assert.ok(el.shadowRoot.querySelector('#later'), 'element not found after default notifying elmeent');
assert.isTrue(el.readySpy.calledOnce, 'ready called more than once');
assert.isTrue(el.handleNotify.calledOnce, 'listener called more than once');
assert.isTrue(el.propChanged.calledOnce, 'observer called more than once');
assert.isTrue(el.handleNotify.calledBefore(el.propChanged), 'observer called before event');
assert.isTrue(el.afterSettingProp.calledBefore(el.propChanged), 'accessor side effect processed during notifying event (before clients ready)');
assert.isTrue(el.propChanged.calledBefore(el.readySpy), 'observer called before ready');
});

});

suite('1-way binding effects between elements', function() {

var el;
Expand Down

0 comments on commit 1f83fd7

Please sign in to comment.