When setting up a unit test suite for an angular application using Karma/Jasmine, is it recommended to include the js with the app module's config
function in the test's files?
I've read that it is suggested to exclude this from testing, however that seems awkward because there's often critical setup that happens in the config
function that would prevent the application from working.
What's the best practice around this? Create a mock config function that does the same thing in a 'mocked' manner?
I'm running across this issue myself but want to understand the broader strategy: How do unit test with angular-translate
In my application, I ended up using the following solution:
Define an "appBase" module with all the
config
andrun
functions that I want to run when unit-testing and create another "app" module which declares "appBase" module as a dependency and includes all theconfig
andrun
functions that I don't what to run when unit-testing. Then all my unit tests use the "appBase" module, while the final application uses the "app" module. In code: