At the moment I'm unable to write unit tests for components that use of the format-message
and intl-get
helpers in the component template.
Initially, this is what I've tried when just setting the test up:
needs: [
'locale:en-GB', 'helper:format-message', 'helper:intl-get'
]
This results in an exception when calling this.render()
in the actual tests:
TypeError: Cannot read property 'on' of undefined
, the stacktrace points to this line. Which makes sense as 'intl:main'
is missing from the needs block.
I tried adding 'intl:main'
to the needs block:
needs: [
'intl:main', 'locale:en-GB',
'helper:format-message', 'helper:intl-get'
]
Which also resulted in an exception:
TypeError: Attempting to register an unknown factory:
intl:main``.
After digging through the ember-intl source I noticed that the ember-intl initializer sets up the intl service as intl:main
instead of service:intl
. Trying to inject service:intl
in the needs block doesn't work either.
My best guess is that initializers don't run in a (module) unit test, resulting in intl:main
never being registered on the container/app. Because the intl-get
helper injects intl:main
rather than service:intl
, adding service:intl
to the test's need block won't do anything.
At the moment, I don't even care what format-message/intl-get renders, stubbing out whatever format-message
and/or intl-get
needs would work just fine for me as well, I just want to be able to render the component's template without exceptions. (I just don't know how to do this)
My actual question(s):
- Am I doing something wrong?
- Is there any documentation that I missed that explains how to do this/make it work?
- If I'm not doing anything wrong, is there a way to work around this (eg. stubbing
intl
on intl-get
)?
Any answers or pointers in the right direction would be greatly appreciated!