Shamoon Shamoon - 4 months ago 31
AngularJS Question

How do I fix 404 warnings with Karma for my AngularJS project?

Running "karma:unit" (karma) task
INFO [karma]: Karma v0.10.9 server started at http://localhost:9876/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Mac OS X)]: Connected on socket lJGhX9DakX2lChvLXtju
WARN [web-server]: 404: /lang/en-US.json
WARN [web-server]: 404: /api/v1/user/session
WARN [web-server]: 404: /api/v1/user/auth

That's what I'm getting... My

files: [
{pattern: 'public/lang/*.*', included: false, served: true}


So that should encompass the lang file, but it does not. Regarding the api calls, those aren't actually served, but I have a check in my app init to try to see if a user is authenticated. In my test file, I'm doing:

$httpBackend.when('GET', '/api/v1/user/session').respond({status: 'ok'});

in my
, but that isn't fixing it. Ideas?

rob rob

If you want to skip your app's config section in a unit test you will need to break your app into multiple modules. That way you can test individual modules without running the config section of another module.

For example if you wanted to unit test your directives without running your app's config section you could do something like this.

var myAppModule = angular.module('myApp', ['myAppDirectives']);

myAppModule.config() {
    //This code won't be run in your unit tests.

var myAppDirectivesModule = angular.module('myAppDirectives', []);

myAppDirectivesModule.directive(/*Define your directives on this module*/);

Then in your unit test where you import the module you can import only the directives module: