how to fix 404 warnings for images during karma unit testing

That is because you need to configurate karma to load then serve them when requested 😉 In your karma.conf.js file you should already have defined files and/or patterns like : // list of files / patterns to load in the browser files : [ {pattern: ‘app/lib/angular.js’, watched: true, included: true, served: true}, {pattern: ‘app/lib/angular-*.js’, watched: … Read more

NPM cannot install dependencies – Attempt to unlock something which hasn’t been locked

As per photusenigma at: https://github.com/npm/npm/issues/4815 Run these commands in a terminal window (note – DON’T replace the $USER part…thats a linux command to get your user!): sudo chown -R $USER ~/.npm sudo chown -R $USER /usr/local/lib/node_modules …and…if you’re on a mac (like I am), and still see errors after running these commands, then run this … Read more

Mocking AngularJS module dependencies in Jasmine unit tests

If you want to mock a module that declare one or more services I have used this code: beforeEach(function(){ module(‘moduleToMock’); module(function ($provide) { $provide.value(‘yourService’, serviceMock); }); }); This is useful if the service you want to mock is also a service that you want to unit test (in another jasmine describe). The solution proposed by … Read more

UI-router interfers with $httpbackend unit test, angular js

Take this gist https://gist.github.com/wilsonwc/8358542 angular.module(‘stateMock’,[]); angular.module(‘stateMock’).service(“$state”, function($q){ this.expectedTransitions = []; this.transitionTo = function(stateName){ if(this.expectedTransitions.length > 0){ var expectedState = this.expectedTransitions.shift(); if(expectedState !== stateName){ throw Error(“Expected transition to state: ” + expectedState + ” but transitioned to ” + stateName ); } }else{ throw Error(“No more transitions were expected! Tried to transition to “+ stateName ); … Read more