Gorgo.Live.ToString()

Mariusz, Gorzoch tech Blog

Posts Tagged ‘AngularJS

Injection in Jasmine with anuglar-mock.js

leave a comment »

So, you’ve build your angular app service and now you would like to test it. Testing simple service without dependencies is not big deal, but when it goes to test services with have some dependencies then it is quite easy to get lost.

Let’s start with basic example, where our service is not depended on others:

http://jsfiddle.net/MariuszGorzoch/81o74pwq/2/

2014-10-06 11-41-00

above service didn’t have any dependencies, so let’s upgrade it:

http://jsfiddle.net/MariuszGorzoch/81o74pwq/5/

2014-10-06 11-40-23

as you can see above in order to inject dependency in our service we need to use $provide.value(‘{serviceWithAreTryingToMock}’, {MockImplementation}); Thanks to that we can mock whatever service we want.

Advertisements

Written by Mariusz Gorzoch

6 October 2014 at 11:49

Posted in Bez kategorii

Tagged with , ,