Skip to content

Commit 65d7734

Browse files
authored
Merge pull request #13772 from chadhietala/rerendering-attrs
[Glimmer2] Add test for glimmer re-renders
2 parents 86d6862 + e59f5af commit 65d7734

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

packages/ember-glimmer/tests/integration/components/curly-components-test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,56 @@ moduleFor('Components test: curly components', class extends RenderingTest {
10131013
this.assertText('In layout - someProp: value set in instance');
10141014
}
10151015

1016+
// Note: Hooks are not re-run for idempotent re-renders
1017+
['@glimmer rerendering component with attrs from parent'](assert) {
1018+
let willUpdate = 0;
1019+
let didReceiveAttrs = 0;
1020+
1021+
this.registerComponent('non-block', {
1022+
ComponentClass: Component.extend({
1023+
didReceiveAttrs() {
1024+
didReceiveAttrs++;
1025+
},
1026+
1027+
willUpdate() {
1028+
willUpdate++;
1029+
}
1030+
}),
1031+
template: 'In layout - someProp: {{someProp}}'
1032+
});
1033+
1034+
this.render('{{non-block someProp=someProp}}', {
1035+
someProp: 'wycats'
1036+
});
1037+
1038+
assert.equal(didReceiveAttrs, 1, 'The didReceiveAttrs hook fired');
1039+
this.assertText('In layout - someProp: wycats');
1040+
1041+
this.runTask(() => this.rerender());
1042+
1043+
this.assertText('In layout - someProp: wycats');
1044+
assert.equal(didReceiveAttrs, 1, 'The didReceiveAttrs hook fired again');
1045+
assert.equal(willUpdate, 0, 'The willUpdate hook fired once');
1046+
1047+
this.runTask(() => this.context.set('someProp', 'tomdale'));
1048+
1049+
this.assertText('In layout - someProp: tomdale');
1050+
assert.equal(didReceiveAttrs, 2, 'The didReceiveAttrs hook fired again');
1051+
assert.equal(willUpdate, 1, 'The willUpdate hook fired again');
1052+
1053+
this.runTask(() => this.rerender());
1054+
1055+
this.assertText('In layout - someProp: tomdale');
1056+
assert.equal(didReceiveAttrs, 2, 'The didReceiveAttrs hook fired again');
1057+
assert.equal(willUpdate, 1, 'The willUpdate hook fired again');
1058+
1059+
this.runTask(() => this.context.set('someProp', 'wycats'));
1060+
1061+
this.assertText('In layout - someProp: wycats');
1062+
assert.equal(didReceiveAttrs, 3, 'The didReceiveAttrs hook fired again in the R step');
1063+
assert.equal(willUpdate, 2, 'The willUpdate hook fired again in the R step');
1064+
}
1065+
10161066
['@htmlbars rerendering component with attrs from parent'](assert) {
10171067
let willUpdate = 0;
10181068
let didReceiveAttrs = 0;

0 commit comments

Comments
 (0)