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

element doesn't exist on type TestContext #1306

Closed
eugenioenko opened this issue Dec 22, 2022 · 2 comments
Closed

element doesn't exist on type TestContext #1306

eugenioenko opened this issue Dec 22, 2022 · 2 comments

Comments

@eugenioenko
Copy link

eugenioenko commented Dec 22, 2022

After this PRs have been merged
#1302
related to this one
#1301

The TextContext type doesn't have an element property defined.

module('Integration | Helper | helper', function (hooks) {
  setupRenderingTest(hooks);
  test('it renders', async function (assert) {
    await render(hbs`something`);
     /* 
      type warning here, property element doesnt exist in TestContext 
     */
    assert.equal(this.element?.textContent?.trim(), 'something');
  });
});

The issue seems to be that TestContext inherits from BaseContext and neither define an element property.
Before the PR 1302 was merged the BaseContext was a dictionary {[key: string]: unknown} and so element could be defined but without unknown as type. Now that BaseContext has been switched to an object, element is not a property of object

@chriskrycho
Copy link
Contributor

chriskrycho commented Dec 22, 2022

That's correct! The main TestContext doesn’t have that on it, so this was a deeply unsafe type which could (and did) lead people astray. See the ember-qunit v6.1 migration guide for a discussion of a few options here, including explicitly specifying the (unsafe, but at least safer!) this: RenderingTestContext parameter and switching to qunit-dom—the latter being the recommended path. (There's a very useful codemod to convert your tests to using qunit-dom; we ran it across the millions of lines of tests for LinkedIn.com a few years ago and haven't looked back!)

@chriskrycho chriskrycho closed this as not planned Won't fix, can't repro, duplicate, stale Dec 22, 2022
@eugenioenko
Copy link
Author

I see, thank you for the clarification and the provided solutions, really appreciated 👍

MrChocolatine added a commit to DazzlingFugu/ember-feature-controls that referenced this issue Nov 11, 2023
MrChocolatine added a commit to DazzlingFugu/ember-feature-controls that referenced this issue Nov 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants