New Rule: No this.element in tests
Couldn't find a lint rule for this, but I would like to catch accidental usages of this.element in integration tests. I think that's an anitpattern now?
Is it? It's still in component test blueprints
hmm, does that work with Glimmer components?
Ohhh I see, you're talking about the "wrapper element" of the component. Yeah that would not make sense with Glimmer components.
I think though, that this.element in a test is instead referring to the test container element. #ember-testing or similar.
I can't find a great link that spells that out, but a lot of the test helper files refer to this as rootElement or something similar. And I log out this.element in an integration test in my app I get: <div id="ember-testing" class="ember-application">
ah ok, my mistake then. I thought it referred to the component's outer element. Maybe I'm thinking of this.$() or whatever the jquery thing was.
I'm ok with closing this if this.element is ok to keep using. But this maybe it still makes sense to nudge towards find() ?
this.element refers to the main test container element and works in all types of test that actually do rendering (setupApplicationTest / setupRenderingTest).
The meaning of this.element has a couple of small quirks depending on the status of the various optional features, but in octane apps it is very clear.
But this maybe it still makes sense to nudge towards find() ?
In general I dislike suggesting find for a few reasons:
- needing a special
findAPI makes it seem like there is some sort of magic going on (in the past there was), the fact that it is "just" a DOM element that you can interact with is much clearer withthis.elementoverfind - forgetting to import leads to mega trolling (window.find is a thing)
- usage of
assert.domaccommodate lots of the use cases where manual querying is done
Ironically, I didn't even want to add a find. The only reason I did was to make migration from the older apis easier, though at this point it would probably be hard to deprecate.