Best way to unit test I18nContext as Cannot read properties of undefined (reading 'lang') #555
Unanswered
BenSegniBA
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
A quick question, as I've looked about the web and haven't found anything so far.
I have a message service which makes use of the I18nService as a dependency and also
I18nContext.current().lang
in order to set the desired language.Inside my message service I have created a simple message method that returns a translated string based on status code:
This all works fine and translations return when I manually test the
currentLanguage
constant.The issue I have is unit testing the service.
I have created a basic mocki18nservice, but when the method is triggered in the test, I consistently get:
TypeError: Cannot read properties of undefined (reading 'lang')
Has anyone found a way of mocking this yet? I have looked over multiple projects using the package, but there isn't any test files on show to see how this has been done in the past.
Beta Was this translation helpful? Give feedback.
All reactions