diff --git a/text/1203-deprecate-get-set-test-context.md b/text/1203-deprecate-get-set-test-context.md index cb29c01e43..5ddbe922c9 100644 --- a/text/1203-deprecate-get-set-test-context.md +++ b/text/1203-deprecate-get-set-test-context.md @@ -12,29 +12,20 @@ prs: project-link: --- -# Deprecate `this.get` and `this.set` on Test Contexts +# Deprecate `get`, `set`, `getProperties`, and `setProperties` 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. +Deprecate the four data-manipulation methods that `@ember/test-helpers` installs on the test context: `this.get`, `this.set`, `this.getProperties`, and `this.setProperties`. ## 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. +[RFC #785](https://github.com/emberjs/rfcs/blob/main/text/0785-remove-set-get-in-tests.md) shipped replacements for these methods. We believe that rendering tests should be using the replacements: `render` accepting a component, and `rerender`, landed in `@ember/test-helpers` 2.8.0, backed by `renderSettled` from `@ember/renderer` in `ember-source` 4.5.0. ## Transition Path -### Before (deprecated) + +### Before ```js import { render } from '@ember/test-helpers'; @@ -45,24 +36,25 @@ test('it renders the name', async function (assert) { await render(hbs``); - assert.dom('[data-test-name]').hasText(this.get('name')); + assert.dom('[data-test-name]').hasText('Zoey'); this.set('name', 'Tomster'); - assert.dom('[data-test-name]').hasText(this.get('name')); + assert.dom('[data-test-name]').hasText('Tomster'); }); ``` -### After (recommended) +### After ```js import { render, rerender } from '@ember/test-helpers'; -import { tracked } from '@glimmer/tracking'; +import { trackedObject } from '@ember/reactive/collections'; +import MyComponent from 'my-app/components/my-component'; test('it renders the name', async function (assert) { - const state = new class { - @tracked name = 'Zoey'; - }; + const state = trackedObject({ + name: 'Zoey', + }); await render(); @@ -75,76 +67,75 @@ test('it renders the name', async function (assert) { }); ``` -For projects that have not yet adopted `