Skip to content

Instantly share code, notes, and snippets.

@james-huston
Last active December 21, 2015 22:59
Show Gist options
  • Save james-huston/6379433 to your computer and use it in GitHub Desktop.
Save james-huston/6379433 to your computer and use it in GitHub Desktop.
Test and angular service by injecting a fake mock dependency
describe('When using the SocketClient provider', function () {
var client, mockEngineio, globalComms;
beforeEach(module(function ($provide) {
mockEngineio = {
connect: function (data) {
throw new Error('blarg!');
},
$get: function () {
console.log('boogers');
return {
socket: function () {}
};
}
};
$provide.provider('engineio', mockEngineio);
}));
beforeEach(function () {
module('Core.Services.SocketClient');
module('Services.Communicator');
inject(function ($injector, Communicator, $rootScope) {
client = $injector.invoke('socketclient', function (socketclient) {
return socketclient;
});
globalComms = Communicator;
});
});
describe('and testing the basics it', function () {
it('should do something...', function () {
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment