Updated: Since this is an older project, I didn't use any module loader. Instead, I imported all dependencies in my index.html
using the script
tag.
The structure of my AngularJS looks like this:
- app.js
angular.module('app', ['LocalStorageModule', 'ngCookies', ...])
- testController
angular.module('app').controller('testController', function(){})
Now, when I try to test the testController
, here's how my jest unit testing code looks like:
- testController.spec.js
require('./testController.controller')
describe('TestController', () => {
beforeEach(angular.mock.module('app'));
})
However, I encountered an error:
Module 'app' is not available
This indicates that I need to import app.js
, but doing so also results in another error:
Failed to instantiate module LocalStorageModule due to: Module 'LocalStorageModule' is not available!
So, do I have to import all twenty or more dependencies installed by bower in every test file? This doesn't seem like a good approach. How can I better handle and import all my components installed via bower?