ember-cli-yadda
ember-cli-yadda copied to clipboard
`this.element` missing in acceptance tests
All the properties that setupApplicationTest()
sets up on your test's this
context exist properly, except for element
(the tests's root element). This is due to two unfortunate coincidences:
-
this.element
is set up lazily after the firstvisit()
call here: https://github.com/emberjs/ember-test-helpers/blob/cce178256ae0e2946c76961fee29fa6d6df6f2fc/addon-test-support/%40ember/test-helpers/setup-application-context.js#L23-L27 - yadda does not preserve the context instance, but rather copies all props over to its own context at the beginning of a test run: https://github.com/acuminous/yadda/blob/bd3b74b72bcecdcf2ffa9937b6d0cbc1a36ce03d/lib/Yadda.js#L25
This means the lazily added element
does not get added to the actual yadda context that the step function will see, so this.element
is undefined there.
Don't know yet how to best fix this. For now you can workaround this by not using this.element
but find()
/findAll()
(exposed by @ember/test-helpers
) instead!
The code from ember-test-helpers
has no dependencies:
if (EmberENV._APPLICATION_TEMPLATE_WRAPPER !== false) {
context.element = document.querySelector('#ember-testing > .ember-view');
} else {
context.element = document.querySelector('#ember-testing');
}
It looks pretty safe to be copied over to ember-cli-yadda
.
Alternatively, we could work with ember-test-helpers
to expose it as an utility function, so that it can be reused in other addons.