Skip to content

Commit

Permalink
Add tests for adding/removing runtime property effects.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Apr 12, 2017
1 parent 1cf955b commit 1471106
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/unit/property-effects-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,20 @@
assertAllPropValues(el, sd, ld, 'path', 'obj.path+++', 4);
});

test('prototypical stamping not affected by runtime stamping', () => {
assertStampingCorrect(el, el.$);
let stamped = el.shadowRoot.querySelectorAll('x-element#first');
assert.equal(stamped.length, 1);
assert.equal(stamped[0], el.$.first);
// Lifecycle order correct
assert.deepEqual(Polymer.lifecycleOrder.ready, [
'x-runtime|x-element#proto|x-element-child#noBinding',
'x-runtime|x-element#proto|x-element-child#hasBinding',
'x-runtime|x-element#proto',
'x-runtime'
]);
});

});

suite('template parsing hooks', () => {
Expand Down
59 changes: 59 additions & 0 deletions test/unit/property-effects.html
Original file line number Diff line number Diff line change
Expand Up @@ -1400,6 +1400,65 @@

});

suite('runtime effects', function() {

var el;

setup(function() {
el = document.createElement('x-basic');
document.body.appendChild(el);
});

teardown(function() {
document.body.removeChild(el);
});

test('add/remove runtime property effect', function() {
assert.equal(el.observerCounts.valueChanged, 1);
let info = {};
let fn = sinon.spy();
let effect = { info, fn };
el._addPropertyEffect('value', el.PROPERTY_EFFECT_TYPES.OBSERVE, effect);
el.value = 'value++';
assert.equal(el.observerCounts.valueChanged, 2);
assert.equal(fn.callCount, 1);
assert.equal(fn.firstCall.args[0], el);
assert.equal(fn.firstCall.args[1], 'value');
assert.equal(fn.firstCall.args[2].value, 'value++');
assert.equal(fn.firstCall.args[4], info);
el._removePropertyEffect('value', el.PROPERTY_EFFECT_TYPES.OBSERVE, effect);
el.value = 'value+++';
assert.equal(fn.callCount, 1);
});

test('add/remove runtime path effect', function() {
assert.equal(el.observerCounts.valueChanged, 1);
let info = {};
let fn = sinon.spy();
let trigger = {name: 'value.path', structured: true};
let effect = { info, fn, trigger };
el._addPropertyEffect('value', el.PROPERTY_EFFECT_TYPES.OBSERVE, effect);
el.value = {path: 'value.path'};
assert.equal(el.observerCounts.valueChanged, 2);
assert.equal(fn.callCount, 1);
assert.equal(fn.getCall(0).args[0], el);
assert.equal(fn.getCall(0).args[1], 'value');
assert.equal(fn.getCall(0).args[2].value, el.value);
assert.equal(fn.getCall(0).args[4], info);
el.set('value.path', 'value.path++');
assert.equal(el.observerCounts.valueChanged, 2);
assert.equal(fn.callCount, 2);
assert.equal(fn.getCall(1).args[0], el);
assert.equal(fn.getCall(1).args[1], 'value.path');
assert.equal(fn.getCall(1).args[2]['value.path'], 'value.path++');
assert.equal(fn.getCall(1).args[4], info);
el._removePropertyEffect('value', el.PROPERTY_EFFECT_TYPES.OBSERVE, effect);
el.set('value.path', 'value.path+++');
assert.equal(fn.callCount, 2);
});

});

</script>

</body>
Expand Down

0 comments on commit 1471106

Please sign in to comment.