Last post we talked about how to setup Karma with mocha and chai. This post we see some particularities in setting up Karma to test Angular apps.
angular-mocks to circumvent this problem.
First, install angular mocks.
bower install angular-mocks --save-dev
karma.config.js to include Angular mocks.
files: [ "node_modules/chai/chai.js", "src/vendor/angular/angular.js", "src/vendor/angular-mocks/angular-mocks.js", "src/js/app.js", "tests/**/*.js" ],
Finally, ensure the module to test is ready by including the following in each test:
This will make the specific module ready to be tested. So all controllers and services defined on the module are available for testing.
You'll find an example on github.