Gorgo.Live.ToString()

Mariusz, Gorzoch tech Blog

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 , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: