Tag Archives: SinonJS

Unit testing Meteor applications with Velocity, Jasmine and SinonJS


via Unit testing Meteor applications with Velocity.

In my previous tutorial I explained some of the basic features of Meteor, a full stack JavaScript platform. In this tutorial I will go more in depth about testing a Meteor application, by testing the chat application we wrote in the previous tutorial.
In this first part I’ll show you how to unit test your Meteor application using the Velocity platform.

Unit testing Meteor applications with Velocity, Jasmine and SinonJS


via Unit testing Meteor applications with Velocity.

In my previous tutorial I explained some of the basic features of Meteor, a full stack JavaScript platform. In this tutorial I will go more in depth about testing a Meteor application, by testing the Chat application we wrote in the previous tutorial.
In this first part I’ll show you how to unit test your Meteor application using the Velocity platform.

Increase Your JavaScript Productivity With Stubs, Improving Tests In The Process


via Increase Your JavaScript Productivity With Stubs, Improving Tests In The Process – Toggl Blog.

It’s very common to have to write applications or libraries with dependencies that are completely foreign to your code. Regardless of whether it’s a database server, a web-service, some CLI-tools or even timers, suddenly your tests spend several seconds waiting for responses and/or don’t have strictly defined behavior. It’d be great if we could define foreign behavior programatically. Instead of actually interacting with them, we could just test our interactions.

The solution for this problem exists and is very simple: using stubs. Knowing how to use them will make your tests easier to write, predictable and a whole lot faster.

In this post, I’ll explain what are stubs through examples, a simple implementation of a stub, sinon.js usage with mocha and my project mocha-make-stub.

Using MochaJS, ChaiJS and SinonJS to Test your Frontend JavaScript Code


via Using Mocha JS, Chai JS and Sinon JS to Test your Frontend JavaScript Code | via @codeship.

This is a republished blog post by Nicolas Perriault. When I first read it I immediately thought it would fit perfectly on our Codeship blog. You may know Nicolas for his awesome CasperJS (an open source navigation scripting & testing utility written in Javascript for PhantomJS) or from various of his talks. We highly recommend following Nicolas on twitter and checking out his website.

As rich Web application complexity grows, if you want to keep your sanity, you need to unit test your frontend JavaScript code.

For the 4 past months, I’ve been working for Mozilla on some big project where such testing strategy was involved. While I wish we could use CasperJS in this perspective, Firefox wasn’t supported at the time and we needed to ensure proper compatibility with its JavaScript engine. So we went with using Mocha, Chai and Sinon and they have proven to be a great workflow for us so far.

Testing JavaScript applications with sinon.js


Click to Read

As developers, we know how important testing our code is and furthermore how much we can gain from automating these tests. That said, most modern web systems are inherently difficult to test due to their interconnected nature. Depending on the architecture of your application it’s at best tedious to test just your code and at worst impossible.

Why is interconnectivity a problem you might ask? Consider an API which pulls information from third party sources. You really only need to test that your code is behaving correctly; the third party sources are out of your control. By creating a system that relies on external data sources you have created a dependency on testing those sources – in order to confirm that your code behaves correctly it needs to send and receive data from the third party source. This makes unit testing nearly impossible and functional testing slow at best and unreliable at worst.

It doesn’t have to be this way though. One of the oft-maligned but actually quite useful features of JavaScript is its prototypal object oriented design. It’s confusing at first if you have little experience with object oriented programming to begin with or are more familiar with classical object oriented programming, but it holds the key to solving our problem of external dependencies when testing.