Angular 2 – Testing

Rick HerrmannWriting tests has been something I’ve been a proponent of for many years.  My testing experience started with C# and then continued on the front end with javascript and Angular 1.  So when I started learning Angular 2, I naturally wanted to see what the testing story was.

The front-end testing I’ve done in the past has always had some friction with respect to getting the tools setup properly.  Mostly I have used Jasmine as the testing framework, which is pretty self contained – but to get a node test server setup properly there are a variety of other npm modules and karma configuration settings to deal with.  I previously wrote about how the angular-cli makes it easy to get an Angular 2 project setup, and this includes getting the test tools setup as well.  So instead of dealing with configuration settings, you can quickly get to just writing tests.

Continue reading “Angular 2 – Testing”

Javascript Testing with Jasmine

Rick HerrmannOne of the features I like about Jasmine is that the ability to mock objects and do interaction based testing is built into the tool.  When testing C# code (with NUnit, MSTest, or even NSpec) you have to pull in another tool to handle mocking.

In Jasmine, mock objects are called spies.  Accordingly, there is a built-in function called spyOn, which takes two parameters:

Continue reading “Javascript Testing with Jasmine”

Testing Your Javascript Code with Jasmine

Rick HerrmannI find myself writing more javascript code these days.  So with more functionality and business rule logic moving to the client side – we need a way to test this code.  There are numerous javascript testing tools that have sprung up in the last year or so.  One of the more popular ones is Jasmine (  Jasmine is a BDD style framework for unit testing javascript.  To get started you can download the zip file from GitHub (

Continue reading “Testing Your Javascript Code with Jasmine”