Skip to content

Testing service with multilevel services dependencies #659

Answered by L2jLiga
akbarsahata asked this question in Q&A
Discussion options

You must be logged in to vote

It's seems like you've missed environment configuration, it's caused because VariableService imports VariableDAO which imports MySQLCommection service which imports your cleanEnv and even VariableDAO is mocked and not actually instantiated - imports are still loaded and hence your cleanEnv executed which leads to this validation error, nothing wrong with library or mocks, you have to configure your environment variables before tests, e.g. in jest.config.js

See https://dev.to/darkmavis1980/how-to-mock-environmental-variables-with-jest-2j3c for example

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@L2jLiga
Comment options

@akbarsahata
Comment options

Answer selected by akbarsahata
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants