[MUSIC] Okay so I'm back in my code editor, and I'm still in Lecture44 folder. Here, I'm looking at the shoppinglist.controller.spec-v2.js, the version 2 of the same Test setup. I didn't want this test running before so I stuck an x right in front of describe to basically temporarily disable it. So I'm going to remove that x now. The first thing we see is the beforeEach function. And you can see there we have a couple of things we're doing here. First we're creating our mock service called "ShoppingListServiceErrorMock". And second we're actually loading our module that is our application module so we can hook into that and test our controller. Lets take a look as to how we're creating this mock service. The way we're creating it is by letting angular inject the dollar sign provide, the provide service. The provide service has a service method, among other methods, and we're calling the service method. By passing it the name of our service, which is ShoppingListServiceErrorMock, which is our mock service. And right in line we're creating the service for us to use later. And you can see, it's the same type of stuff that you would use when you create a regular service. I created this service local variable and attached a method to it called add item. And created another one called add [INAUDIBLE] getItems, which returns null. Here you could see I'm just returning that error message called with a message test message. So, that's it, now angular knows that such a service called ShoppingList service error mock exists. Let's go down and take a look as to what we're injecting. When we're injecting stuff, we're no longer injecting just the controller that we need to instantiate, we're also injecting the ShoppingListService mock. Just like we would inject any other available service or controller, and so on. We're injecting it right here. This one was not created inside this beforeEach. Instead it was created using angular $provide.service method. So, once we injected it, we could actually provide it as that instance that got injected right here. We could provide it as a value to our dollar sign controller call which basically creates our shopping list controller and passes it in the injected service, in this case with a key ShoppingListService and the injected service instance that we're passing is ShoppingListServiceErrorMock. So exactly the same one as before, except now we're having angular inject it into the beforeEach function. Instead of creating it manually ourselves inside of it. Okay, so the last part is the actual test method. And a test function is exactly the same, we're just calling this add item, which triggers our shopping list service error mock to throw an error. That error gets translated and the controller is supposed to set the error message to be test message, whatever gets returned from that ShoppingListService, which is Test message. And we verify that it is, in fact, the case by calling the expect function. If we go back, now that we saved it, we can see that both specs run and spec version 2 of shopping list controller also run in green and both of them passed with zero failures. Okay, so let's summarize angular provides ngMock module to help us with unit testing of our angular applications. To test a controller you need to do the following. You need to load the module that controller is in with the angular.mock.module. Passing it the name of the module that you developed for your application. Then you used the dollar sign controller or the controller service to instantiate the controller you want to test. You use the controller instance to invoke methods, access properties and so on. Now most of the setup that's done for the test is done in the beforeEach function. The very least thing you should do is at least call the module with the name of the module, but maybe even do some more preparations for your tests or the preparations that all of your tests in your test suite, or set of tests, are sharing between each other. Now there's a couple of ways of creating these mock objects we're going to need in order to control the environment our test runs in. One of them is to create those objects manually. But another one is you could use the dollar sign provide or the provide service that you can inject, but you have to inject it only through the module method that we spoke about before. For other services you can use the regular, angular.mock.inject method and they work just fine, because they resemble regular services as opposed to provide, is really talking about provider services that we spoke about before when we used the .config method that only provider services can be injected into that. As opposed to other artifacts and resources in your angular application. You could use the regular injection method. Then this case, you would use the regular, or the mock version of the regular, mock.inject method.