CodePen, AngularJS, and Jasmine!

Online Web editors, like JSbin, plnkr, and CodePen, are awesome. They allow you to easily work on an idea without all of the muss and fuss of having to spin up a server. You can also share the idea with friends or the entire Internet easily. 

Unit test is something that all developers, especially AngularJS ones, are encouraged to do. I work on a lot of angular ideas initially in CodePen. I also write unit test in Jasmine, but getting the two to play nice together in CodePen wasn’t as easy as I thought it should be. 

In the pen below I show how to get the two working together. The main trouble I was having was the order of the files. It has to be as follows:

  1. jasmine.css
  2. jasmine.js
  3. jasmine-html.js
  4. boot.js 
  5. angular.js
  6. angular-mocks.js
If you get the order wrong, you may get errors like: ReferenceError: inject is not defined or ReferenceError: module is not defined. These can make you think something is wrong with your code when there isn’t. 

The pen below is written using Jasmine 2.0 and AngularJS 1.26.



See the Pen finished-jasmine-unit-test by Troy Miles (@Rockncoder) on CodePen.

//codepen.io/assets/embed/ei.js

Advertisements

One thought on “CodePen, AngularJS, and Jasmine!

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