From 2374dce9e62eb8811a2fff4414ca348be8280b67 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Jun 2026 16:14:04 +0000 Subject: [PATCH] Add RFC 1188: Deprecate .get and .set on test contexts --- text/1188-deprecate-get-set-test-context.md | 150 ++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 text/1188-deprecate-get-set-test-context.md diff --git a/text/1188-deprecate-get-set-test-context.md b/text/1188-deprecate-get-set-test-context.md new file mode 100644 index 0000000000..152a525999 --- /dev/null +++ b/text/1188-deprecate-get-set-test-context.md @@ -0,0 +1,150 @@ +--- +stage: accepted +start-date: 2026-06-22T00:00:00.000Z +release-date: +release-versions: +teams: + - framework + - learning + - typescript +prs: + accepted: # update this to the PR that you propose your RFC in +project-link: +--- + +# Deprecate `this.get` and `this.set` on Test Contexts + +## Summary + +Deprecate the use of `this.get` and `this.set` on the test context object in rendering tests, as a logical conclusion of [RFC #785](https://github.com/emberjs/rfcs/blob/master/text/0785-remove-set-get-in-tests.md), which introduced `render(component)` and `rerender()` as the modern replacements. + +## Motivation + +RFC #785 introduced two new testing utilities — an updated `render` helper that accepts a component directly, and a new `rerender()` function — specifically to remove the need for `this.get` and `this.set` in rendering tests. Those APIs shipped in Ember v4.5.0 and are now the recommended approach for writing rendering tests. + +The legacy pattern of setting values on `this` in a rendering test was problematic for several reasons laid out in RFC #785: + +1. **Inconsistency with application code.** In post-Octane Ember, `get` and `set` are unnecessary; properties are tracked natively. Requiring them in tests is a confusing holdover. + +2. **Incorrect rendering semantics.** `this.set` in tests is run-wrapped, causing a synchronous full DOM flush on every call. This does not reflect how Ember schedules DOM updates in production code, where changes to tracked state are coalesced. + +3. **TypeScript friction.** Assigning arbitrary properties to `this` forces developers to redeclare the `TestContext` interface for every test module, causing leakage of property declarations across tests and defeating the purpose of static type checking. + +Now that the modern replacements have been stable for multiple major versions, it is appropriate to deprecate the old approach and eventually remove it, completing the migration to a cleaner and more accurate testing model. + +## Transition Path + +### Before (deprecated) + +```js +import { render } from '@ember/test-helpers'; +import { hbs } from 'ember-cli-htmlbars'; + +test('it renders the name', async function (assert) { + this.set('name', 'Zoey'); + + await render(hbs``); + + assert.dom('[data-test-name]').hasText(this.get('name')); + + this.set('name', 'Tomster'); + + assert.dom('[data-test-name]').hasText(this.get('name')); +}); +``` + +### After (recommended) + +```js +import { render, rerender } from '@ember/test-helpers'; +import { tracked } from '@glimmer/tracking'; + +test('it renders the name', async function (assert) { + const state = new class { + @tracked name = 'Zoey'; + }; + + await render(); + + assert.dom('[data-test-name]').hasText('Zoey'); + + state.name = 'Tomster'; + await rerender(); + + assert.dom('[data-test-name]').hasText('Tomster'); +}); +``` + +For projects that have not yet adopted `