After following a blog post on setting up an Angular project with webpack, I used an associated boilerplate on Github.
Although the app is functioning properly, Karma seems to have trouble finding the controller it needs to test.
// karma.config.js
module.exports = config => config.set({
files: ['test.webpack.js'],
preprocessors: {
'test.webpack.js': ['webpack', 'sourcemap']
},
browsers: ['PhantomJS2'],
webpack: require('./webpack.config'),
webpackMiddleware: {
noInfo: 'errors-only',
},
});
// test.webpack.js
import 'angular';
import 'angular-mocks/angular-mocks';
const testContext = require.context('./', true, /\.spec\.js$/);
testContext.keys().forEach(testContext);
Currently, I only have one spec file named MainCtrl.spec.js
. Although Karma attempts to run it, I receive the error:
Argument 'MainCtrl' is not a function, got undefined
Interestingly, when I run the actual application, MainCtrl
loads without any issues. It's perplexing why Karma can't access it.
I've experimented with changing \.spec\.js
to simply \.js
, but this approach leads to numerous other errors.