Mocking AMD Modules with Squire.js

Monday, April 20th, 2015

Writing unit tests when working with Require.js is tough. Out of the box, Require.js does not make mocking very easy. It involves setting up a separate Require.js context and a complicated setup in a beforeEach.

Read More

Overriding Backbone.sync

Wednesday, March 18th, 2015

As a frontend developer, you might find yourself in a situation where you have to work with unRESTful endpoints. If you are working with Backbone, Backbone models follow traditional REST. As mentioned in the docs for Backbone.sync():

Read More

End To End Testing with PhantomJS and CasperJS

Saturday, February 28th, 2015

When it comes to testing in JavaScript, I would say that there are two types of tests: unit tests and end to end tests, which are also referred to as integration tests or functional tests depending on who you talk to and what articles you read. For me, I have found unit testing to be beneficial and relatively straightforward for code that does not involve the DOM much. Unit testing allows you to test modules in isolation and is great for (but not limited to) testing things like data structures, data manipulation, validation, etc. But how do you test JavaScript that heavily depends on the DOM and user interactions? How do you test that the different modules of your application work together? This is where end to end testing comes in. In this article we will look at how we can set up a simple end to end testing system using CasperJS, which sits on top of PhantomJS.

Read More

Getting Started with Array.prototype.reduce()

Saturday, February 21st, 2015

Array.prototype.reduce is one of those Array methods in JavaScript that I knew existed but I never really looked into it because I could achieve the same output using Array.prototype.forEach. Recently I decided to learn how it worked and wanted to show a couple examples of how you can transform some code using forEach to using reduce.

Read More

Unit Testing Angular Directives with Isolate Scope

Thursday, February 12th, 2015

If you are building complex user interfaces, you will at some point want to start unit testing your directives. Below is a simple directive called blog-status that displays either “Active” or “Inactive” on the page. This might be a directive used in the admin section for a blog where it shows a list of all your posts and the status of each post. It’s not the most useful directive but it is simple enough to show how to unit test a directive with isolate scope. Usage of this directive would be:

Read More