You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you use `render` on a component and then call `this.set`, you get an assertion:
>'You cannot call `this.set` when passing a component to `render()` (the rendered component does not have access to the test context).',
But that's not true and hasn't been since the introduction of components with access to lexical scope. For example:
```gjs
let self = this;
render(<template>{{self.message}}</template>)
this.set('message', 'updated')
```
My example uses a workaround for emberjs/babel-plugin-ember-template-compilation#61, but we have open PRs fixing that issue in which case this would also just work directly:
```gjs
render(<template>{{this.message}}</template>)
this.set('message', 'updated')
```
Critically, `@embroider/template-tag-codemod` can produce these situations entirely automatically, as it upgrades any existing tests to template tag.
// We use this to track when `render` is used with a component so that we can throw an
138
-
// assertion if `this.{set,setProperty} is used in the same test
139
-
ComponentRenderMap.set(context,true);
140
-
141
-
constsetCalls=SetUsage.get(context);
142
-
143
-
if(setCalls!==undefined){
144
-
assert(
145
-
`You cannot call \`this.set\` or \`this.setProperties\` when passing a component to \`render\`, but they were called for the following properties:\n${setCalls
`Error: Assertion Failed: You cannot call \`this.set\` or \`this.setProperties\` when passing a component to \`render\`, but they were called for the following properties:
683
-
- foo
684
-
- bar
685
-
- baz
686
-
- baq`
687
-
);
688
-
}
689
-
});
690
-
691
-
test('setting properties on the test context *after* rendering a component throws an assertion',asyncfunction(assert){
`Error: Assertion Failed: You cannot call \`this.set\` or \`this.setProperties\` when passing a component to \`render\`, but they were called for the following properties:
840
-
- foo
841
-
- bar
842
-
- baz
843
-
- baq`
844
-
);
845
-
}
846
-
});
847
-
848
-
test('setting properties on the test context *after* rendering a component throws an assertion',asyncfunction(assert){
0 commit comments