Migration Guide ============================================================================== Migrating to native TypeScript support in v6.1.0 ------------------------------------------------------------------------------ The types for the QUnit `TestContext` provided by the `ember-qunit` and `@ember/test-helpers` types on DefinitelyTyped made a choice to prioritize convenience over robustness when it came to what methods and values were available on `this` in any given test: they made _all_ methods availabe regardless of what your setup actually involved. If your tests rely on properties of `this` that aren't actually available in all test contexts, like `this.render` or `this.element`, those tests will now produce type errors. For example, with the 6.1 native types, this test would produce a type error on the line where `this.element` is referenced: ```ts import { module, test } from 'qunit'; import { setupRenderingTest } from 'ember-qunit'; import { hbs } from 'ember-cli-htmlbars'; module('', function (hooks) { setupRenderingTest(hooks); test('greets', async function (assert) { await render(hbs``); assert.equal(this.element.textContent?.trim(), 'Hello!'); }); }); ``` To resolve this, you can explicitly specify what `this` is for different kinds of tests: ```ts import { module, test } from 'qunit'; import { setupRenderingTest } from 'ember-qunit'; import { hbs } from 'ember-cli-htmlbars'; import type { RenderingTestContext } from '@ember/test-helpers'; module('', function (hooks) { setupRenderingTest(hooks); test('greets', async function (this: RenderingTestContext, assert) { await render(hbs``); assert.equal(this.element.textContent?.trim(), 'Hello!'); }); }); ``` In many cases this should not be necessary, though. For instance, if the test above were written using [`qunit-dom`][qunit-dom] instead, no `this` annotation would be needed: ```ts import { module, test } from 'qunit'; import { setupRenderingTest } from 'ember-qunit'; import { hbs } from 'ember-cli-htmlbars'; module('', function (hooks) { setupRenderingTest(hooks); test('greets', async function (assert) { await render(hbs``); assert.dom().hasText('Hello!'); }); }); ``` [qunit-dom]: https://github.com/mainmatter/qunit-dom While annoying, the tighter default type for `this` in tests is accurate and prevents TypeScript from presenting invalid options while authoring tests. Combined with support for using local scope with `