Skip to content

Commit 1f83fd7

Browse files
author
Steven Orvell
committed
Add tests.
1 parent c7a81ea commit 1f83fd7

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

test/unit/property-effects-elements.html

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,39 @@
421421
</script>
422422
</dom-module>
423423

424+
<dom-module id="x-handle-notify-event">
425+
<template>
426+
<slot name="drawer"></slot>
427+
<div id="before"></div>
428+
<x-basic id="basic1"
429+
on-notifyingvalue-with-default-changed="handleNotify">
430+
</x-basic>
431+
<div id="later"></div>
432+
</template>
433+
<script>
434+
Polymer({
435+
is: 'x-handle-notify-event',
436+
properties: {
437+
prop: {
438+
observer: 'propChanged'
439+
}
440+
},
441+
created: function() {
442+
this.readySpy = sinon.spy();
443+
this.afterSettingProp = sinon.spy();
444+
this.propChanged = sinon.spy();
445+
this.handleNotify = sinon.spy(function() {
446+
this.prop = 'prop';
447+
this.afterSettingProp();
448+
});
449+
},
450+
ready: function() {
451+
this.readySpy();
452+
}
453+
});
454+
</script>
455+
</dom-module>
456+
424457
<script>
425458
Polymer({
426459
is: 'x-reflect',

test/unit/property-effects.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,37 @@
633633

634634
});
635635

636+
suite('handling notifying evevnts', function() {
637+
638+
test('handle notifcation event and set property with observer when connected', function() {
639+
var el = document.createElement('x-handle-notify-event');
640+
document.body.appendChild(el);
641+
assert.ok(el.shadowRoot.querySelector('#before'), 'element not found before default notifying elmeent');
642+
assert.ok(el.shadowRoot.querySelector('#later'), 'element not found after default notifying elmeent');
643+
assert.isTrue(el.readySpy.calledOnce, 'ready called more than once');
644+
assert.isTrue(el.handleNotify.calledOnce, 'listener called more than once');
645+
assert.isTrue(el.propChanged.calledOnce, 'observer called more than once');
646+
assert.isTrue(el.handleNotify.calledBefore(el.propChanged), 'observer called before event');
647+
assert.isTrue(el.afterSettingProp.calledBefore(el.propChanged), 'accessor side effect processed during notifying event (before clients ready)');
648+
assert.isTrue(el.propChanged.calledBefore(el.readySpy), 'observer called before ready');
649+
document.body.removeChild(el);
650+
});
651+
652+
test('handle notifcation event and set property with observer when *not* connected and _enableProperties called', function() {
653+
var el = document.createElement('x-handle-notify-event');
654+
el._enableProperties();
655+
assert.ok(el.shadowRoot.querySelector('#before'), 'element not found before default notifying elmeent');
656+
assert.ok(el.shadowRoot.querySelector('#later'), 'element not found after default notifying elmeent');
657+
assert.isTrue(el.readySpy.calledOnce, 'ready called more than once');
658+
assert.isTrue(el.handleNotify.calledOnce, 'listener called more than once');
659+
assert.isTrue(el.propChanged.calledOnce, 'observer called more than once');
660+
assert.isTrue(el.handleNotify.calledBefore(el.propChanged), 'observer called before event');
661+
assert.isTrue(el.afterSettingProp.calledBefore(el.propChanged), 'accessor side effect processed during notifying event (before clients ready)');
662+
assert.isTrue(el.propChanged.calledBefore(el.readySpy), 'observer called before ready');
663+
});
664+
665+
});
666+
636667
suite('1-way binding effects between elements', function() {
637668

638669
var el;

0 commit comments

Comments
 (0)