Major changes are like instead of using Form variable, I have created a scope variable. Next you need to create test runner. You can download the Jasmine files and reference it in a HTML file. You can use this HTML file to view the unit test results. I have included Jasmine and Angular Mocks in bower.json and install it via bower install command. Here is my bower.json file
And here is the Test runner file, with references of the App, Controller and other references. Make sure you’re not changing the order, otherwise Jasmine won’t work.
You can write unit tests after the controller references. You can find unit tests with describe and it global functions. Here is the first sample unit test.
Here is the screenshot of hello world unit test.
For mocking http service angular comes with httpBackend service. And here is the unit tests for CreateToDo and loadTodos functions.
Here is the screenshot
If you look into the code, we are duplicating lot of code. We can refactor using beforeEach function. Here is the refactored version of the unit test code.
In the next post I will cover code coverage using blanket.js. Happy Coding.
What do you think? I would like to hear your thoughts, suggestions, and questions in the comments section below.
Did you like this article? Share it with your friends