Add tests

* When extended, a behavior `registered` is always called on sub-most prototype rather than the prototype on which `registered` was defined.
* behavior property default values are overwritten by later behaviors and elements
* readOnly properties ignored when a previous behavior observes the property
* observedAttributes when extended
This commit is contained in:
Steven Orvell
2018-11-14 10:37:53 -08:00
parent ad5cb2686a
commit f3b6675573
2 changed files with 134 additions and 1 deletions
+64
View File
@@ -397,6 +397,45 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
zot: 'zot'
});
Polymer({
is: 'override-default-value',
behaviors: [
{
properties: {
foo: { value: true },
bar: { value: true}
}
},
{
properties: {
foo: { value: true },
bar: String,
zot: {value: true}
}
},
],
properties: {
foo: String,
zot: String
}
});
Polymer({
is: 'property-observer-readonly',
behaviors: [
{
observers: ['_changed(bar)'],
_changed() {}
}
],
properties: {
bar: {readOnly: true}
}
});
</script>
<test-fixture id="single">
@@ -471,6 +510,18 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
</template>
</test-fixture>
<test-fixture id="override-default-value">
<template>
<override-default-value></override-default-value>
</template>
</test-fixture>
<test-fixture id="property-observer-readonly">
<template>
<property-observer-readonly></property-observer-readonly>
</template>
</test-fixture>
<script type="module">
import { Polymer } from '../../polymer-legacy.js';
@@ -534,6 +585,19 @@ suite('single behavior element', function() {
assert.equal(el.nug, 'nug');
});
test('behavior default values can be overridden', function() {
const el = fixture('override-default-value');
assert.notOk(el.foo);
assert.notOk(el.bar);
assert.notOk(el.zot);
});
test('readOnly not applied when property was previously observed', function() {
const el = fixture('property-observer-readonly');
el.bar = 5;
assert.equal(el.bar, 5);
});
});
suite('behavior.registered', function() {
+70 -1
View File
@@ -389,6 +389,48 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
customElements.define('before-register-observers', klass);
</script>
<script type="module">
import { mixinBehaviors } from '../../lib/legacy/class.js';
import { PolymerElement } from '../../polymer-element.js';
const Base = mixinBehaviors([{
registered() {
this.usedExtendedProto = this.canUseExtendedProto;
}
}], PolymerElement);
customElements.define('registered-proto', mixinBehaviors([
{canUseExtendedProto: true}
], Base));
</script>
<script type="module">
import { mixinBehaviors } from '../../lib/legacy/class.js';
import { PolymerElement } from '../../polymer-element.js';
class Base extends mixinBehaviors([{
properties: {b1: String} }], PolymerElement) {
static get properties() {
return { e1: String};
}
}
class El extends mixinBehaviors([{
properties: {b2: String}}], Base) {
static get properties() {
return { e2: String};
}
}
customElements.define('extended-observed-attributes', El);
</script>
<test-fixture id="single">
<template>
<single-behavior></single-behavior>
@@ -436,6 +478,20 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
<behavior-registered-ext></behavior-registered-ext>
</template>
</test-fixture>
<test-fixture id="registered-proto">
<template>
<registered-proto></registered-proto>
</template>
</test-fixture>
<test-fixture id="extended-observed-attributes">
<template>
<extended-observed-attributes b1="b1" e1="e1" b2="b2" e2="e2"></extended-observed-attributes>
</template>
</test-fixture>
<script type="module">
import { Polymer } from '../../polymer-legacy.js';
import { mixinBehaviors } from '../../lib/legacy/class.js';
@@ -508,7 +564,12 @@ suite('behavior.registered/beforeRegister', function() {
var el = fixture('before-register-observers');
el.foo = 1;
assert.equal(el.__fooChangedCalled, 1);
});
});
test('registered called on class prototype when extended', function() {
var el = fixture('registered-proto');
assert.isTrue(el.usedExtendedProto);
});
});
@@ -657,6 +718,14 @@ suite('extended-behaviors', function() {
assert.deepEqual(el.__createdList, ['1', '2', 'sup', '3', '4', 'sub'], 'created list wrong');
});
test('observedAttributes when extended', function() {
const el = fixture('extended-observed-attributes');
assert.equal(el.b1, 'b1');
assert.equal(el.e1, 'e1');
assert.equal(el.b2, 'b2');
assert.equal(el.e2, 'e2');
});
});
</script>