mirror of
https://github.com/Polymer/polymer.git
synced 2025-02-25 18:55:30 -06:00
Make the test more look like a spec
This commit is contained in:
parent
56df8f7346
commit
db7c32491c
@ -487,7 +487,7 @@
|
||||
</script>
|
||||
</dom-module>
|
||||
|
||||
<dom-module id="x-order-of-effects-parent">
|
||||
<dom-module id="x-order-of-effects-grand-parent">
|
||||
<template>
|
||||
<x-order-of-effects id="child" base="{{base}}"></x-order-of-effects>
|
||||
</template>
|
||||
@ -495,22 +495,23 @@
|
||||
|
||||
<dom-module id="x-order-of-effects">
|
||||
<template>
|
||||
<x-order-of-effects-child prop="{{base}}"></x-order-of-effects-child>
|
||||
<div id="child">{{_computedAnnotation(base)}}</div>
|
||||
<x-order-of-effects-child
|
||||
prop1="[[base]]"
|
||||
prop2="[[_computedAnnotation(base)]]"
|
||||
></x-order-of-effects-child>
|
||||
</template>
|
||||
<script>
|
||||
(function() {
|
||||
var invocations = 0;
|
||||
var invocations = [];
|
||||
Polymer({
|
||||
is: 'x-order-of-effects-child',
|
||||
is: 'x-order-of-effects-grand-parent',
|
||||
properties: {
|
||||
prop: {
|
||||
type: String,
|
||||
observer: '_childProp'
|
||||
base: {
|
||||
observer: '_childPropertyChanged'
|
||||
}
|
||||
},
|
||||
_childProp: function(prop) {
|
||||
assert.equal(invocations++, 1);
|
||||
_childPropertyChanged: function() {
|
||||
invocations.push('notify');
|
||||
}
|
||||
});
|
||||
Polymer({
|
||||
@ -533,37 +534,43 @@
|
||||
},
|
||||
observers: ['_complexObserver(complex, base)'],
|
||||
ready: function() {
|
||||
this.invocations = invocations;
|
||||
|
||||
var old = this.reflectPropertyToAttribute.bind(this);
|
||||
this.reflectPropertyToAttribute = function(property, attribute, value) {
|
||||
assert.equal(invocations++, 3);
|
||||
invocations.push('reflect');
|
||||
old(property, attribute, value);
|
||||
};
|
||||
},
|
||||
_computed: function(base) {
|
||||
assert.equal(invocations++, 0);
|
||||
invocations.push('compute');
|
||||
return base;
|
||||
},
|
||||
_computedAnnotation: function(base) {
|
||||
assert.equal(invocations++, 2);
|
||||
return base;
|
||||
},
|
||||
_observer: function() {
|
||||
assert.equal(invocations++, 5);
|
||||
invocations.push('observer');
|
||||
},
|
||||
_complexObserver: function() {
|
||||
assert.equal(invocations++, 6);
|
||||
invocations.push('complexObserver');
|
||||
}
|
||||
});
|
||||
Polymer({
|
||||
is: 'x-order-of-effects-parent',
|
||||
is: 'x-order-of-effects-child',
|
||||
properties: {
|
||||
base: {
|
||||
type: String,
|
||||
observer: '_childPropertyChanged'
|
||||
prop1: {
|
||||
observer: '_prop1Changed'
|
||||
},
|
||||
prop2: {
|
||||
observer: '_prop2Changed'
|
||||
}
|
||||
},
|
||||
_childPropertyChanged: function() {
|
||||
assert.equal(invocations++, 4);
|
||||
_prop1Changed: function() {
|
||||
invocations.push('annotation');
|
||||
},
|
||||
_prop2Changed: function() {
|
||||
invocations.push('annotatedComputation');
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
@ -861,11 +861,24 @@ suite('order of effects', function() {
|
||||
var el;
|
||||
|
||||
setup(function() {
|
||||
el = document.createElement('x-order-of-effects-parent').$.child;
|
||||
el = document.createElement('x-order-of-effects-grand-parent').$.child;
|
||||
});
|
||||
|
||||
test('effects are sorted', function() {
|
||||
assert.equal(el.invocations.length, 0);
|
||||
el.base = 'changed';
|
||||
|
||||
var expected = [
|
||||
'compute',
|
||||
'annotation', // as observed by child
|
||||
'annotatedComputation', // as observed by child
|
||||
'reflect',
|
||||
'notify', // as observed by grand-parent
|
||||
'observer',
|
||||
'complexObserver'
|
||||
];
|
||||
|
||||
assert.deepEqual(el.invocations, expected);
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user