Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove incorrect assertions #1527

Merged
merged 1 commit into from
Jan 17, 2025
Merged

Conversation

ef4
Copy link
Contributor

@ef4 ef4 commented Jan 16, 2025

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:

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:

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. So whether you think it's good for new code to use this.set in tests, as we codemod all templates to template tag, existing tests that use this.set are going to hit this assertion unnecessarily.

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.
@ef4 ef4 force-pushed the remove-incorrect-assertions branch from 419b1fa to 7e0340f Compare January 16, 2025 22:33
@NullVoxPopuli NullVoxPopuli merged commit d158041 into master Jan 17, 2025
22 checks passed
@NullVoxPopuli NullVoxPopuli deleted the remove-incorrect-assertions branch January 17, 2025 14:18
@github-actions github-actions bot mentioned this pull request Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants