From 14711067e25dc6bf72f8019e29705b4055023ff9 Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Tue, 11 Apr 2017 18:36:58 -0700 Subject: [PATCH] Add tests for adding/removing runtime property effects. --- test/unit/property-effects-template.html | 14 ++++++ test/unit/property-effects.html | 59 ++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/test/unit/property-effects-template.html b/test/unit/property-effects-template.html index ea2b7f8198..777b1e43ad 100644 --- a/test/unit/property-effects-template.html +++ b/test/unit/property-effects-template.html @@ -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', () => { diff --git a/test/unit/property-effects.html b/test/unit/property-effects.html index e59a6e2a92..3de0bfb660 100644 --- a/test/unit/property-effects.html +++ b/test/unit/property-effects.html @@ -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); + }); + +}); +