Make the test more look like a spec

This commit is contained in:
herr kaste 2016-02-05 23:28:47 +01:00
parent 56df8f7346
commit db7c32491c
2 changed files with 42 additions and 22 deletions

View File

@ -487,7 +487,7 @@
</script> </script>
</dom-module> </dom-module>
<dom-module id="x-order-of-effects-parent"> <dom-module id="x-order-of-effects-grand-parent">
<template> <template>
<x-order-of-effects id="child" base="{{base}}"></x-order-of-effects> <x-order-of-effects id="child" base="{{base}}"></x-order-of-effects>
</template> </template>
@ -495,22 +495,23 @@
<dom-module id="x-order-of-effects"> <dom-module id="x-order-of-effects">
<template> <template>
<x-order-of-effects-child prop="{{base}}"></x-order-of-effects-child> <x-order-of-effects-child
<div id="child">{{_computedAnnotation(base)}}</div> prop1="[[base]]"
prop2="[[_computedAnnotation(base)]]"
></x-order-of-effects-child>
</template> </template>
<script> <script>
(function() { (function() {
var invocations = 0; var invocations = [];
Polymer({ Polymer({
is: 'x-order-of-effects-child', is: 'x-order-of-effects-grand-parent',
properties: { properties: {
prop: { base: {
type: String, observer: '_childPropertyChanged'
observer: '_childProp'
} }
}, },
_childProp: function(prop) { _childPropertyChanged: function() {
assert.equal(invocations++, 1); invocations.push('notify');
} }
}); });
Polymer({ Polymer({
@ -533,37 +534,43 @@
}, },
observers: ['_complexObserver(complex, base)'], observers: ['_complexObserver(complex, base)'],
ready: function() { ready: function() {
this.invocations = invocations;
var old = this.reflectPropertyToAttribute.bind(this); var old = this.reflectPropertyToAttribute.bind(this);
this.reflectPropertyToAttribute = function(property, attribute, value) { this.reflectPropertyToAttribute = function(property, attribute, value) {
assert.equal(invocations++, 3); invocations.push('reflect');
old(property, attribute, value); old(property, attribute, value);
}; };
}, },
_computed: function(base) { _computed: function(base) {
assert.equal(invocations++, 0); invocations.push('compute');
return base; return base;
}, },
_computedAnnotation: function(base) { _computedAnnotation: function(base) {
assert.equal(invocations++, 2);
return base; return base;
}, },
_observer: function() { _observer: function() {
assert.equal(invocations++, 5); invocations.push('observer');
}, },
_complexObserver: function() { _complexObserver: function() {
assert.equal(invocations++, 6); invocations.push('complexObserver');
} }
}); });
Polymer({ Polymer({
is: 'x-order-of-effects-parent', is: 'x-order-of-effects-child',
properties: { properties: {
base: { prop1: {
type: String, observer: '_prop1Changed'
observer: '_childPropertyChanged' },
prop2: {
observer: '_prop2Changed'
} }
}, },
_childPropertyChanged: function() { _prop1Changed: function() {
assert.equal(invocations++, 4); invocations.push('annotation');
},
_prop2Changed: function() {
invocations.push('annotatedComputation');
} }
}); });
})(); })();

View File

@ -861,11 +861,24 @@ suite('order of effects', function() {
var el; var el;
setup(function() { 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() { test('effects are sorted', function() {
assert.equal(el.invocations.length, 0);
el.base = 'changed'; 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);
}); });
}); });