Skip to content

Commit

Permalink
Make the test more look like a spec
Browse files Browse the repository at this point in the history
  • Loading branch information
kaste committed Feb 5, 2016
1 parent 56df8f7 commit db7c324
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 22 deletions.
49 changes: 28 additions & 21 deletions test/unit/bind-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -487,30 +487,31 @@
</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>
</dom-module>

<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({
Expand All @@ -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');
}
});
})();
Expand Down
15 changes: 14 additions & 1 deletion test/unit/bind.html
Original file line number Diff line number Diff line change
Expand Up @@ -861,11 +861,24 @@
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);
});
});

Expand Down

0 comments on commit db7c324

Please sign in to comment.