Tag Archives: Mocha

Client-side testing with Mocha and Karma

via Client-side testing with Mocha and Karma | Sean Coker.

Client-side JavaScript testing is still pretty young in 2015, partly due to the overhead required before you can actually get tests running. From learning all the individual tools that work together to restructuring your code so it can actually be tested, it could be a while before you get up and running. Hopefully this guide will make things a little bit easier.

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.

Server side testing with Mocha for NodeJS

via Server side testing with Mocha for Node.js – Technical Blogs : Technical Blogs.

This article is a continuation of our previous articles about Single Page Application with Angular.js, Node.js and MongoDB part 1 and part 2.

In general, we appreciate unit testing in application, because at the time of delivery, we have much confidence about our piece of software regarding non-breaking of the code-base in production. There are integration tests, regression tests in our application, but we do not include those part in current scope of article, rather we emphasis on unit testing from development perspective.

We tried to cover the tests of methods of server side here. We expect, reader is already have some knowledge about unit testing of components in any given application. A test driven environment always help us through development life cycle for better maintainability of code-base and less iteration on bug fixing.

Testing your frontend JavaScript code using mocha, chai, and sinon

via Testing your frontend JavaScript code using mocha, chai, and sinon | Code | Nicolas Perriault.

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.

Getting started with NodeJS and Mocha

via Getting started with Node.js and Mocha – Semaphore.

Mocha is a testing library for Node.js, created to be a simple, extensible, and fast testing suite. It is used for unit and integration testing, and it’s a great candidate for BDD (Behavior Driven Development).

This article will walk you through its installation and configuration, and also it will demonstrate its usage by implementing a color converter that can translate from RGB (red, green, blue) to hexadecimal color representation. In addition, we will create a web server that exposes the above converter, and demonstrates how to test asynchronous code.

Continuous Delivery in Minutes with NodeJS, Grunt, Mocha and Git

via Continuous Delivery in Minutes with Node.js, Grunt, Mocha and Git – Steven Edouard.

Modern application development now’a’days demands a rigorous continuous deliver mechanism. This is especially true when it comes to the cloud.

You want to be able to get through the Build -> Measure -> Learn cycle as fast as possible. With cloud services, you can quickly create mechanisms to build, test and deploy your development team’s code. You can even maintain development and production branches.

The lab below will take you through this process and can be done on any computer that can run NodeJS.

Test helpers for using mongodb with mocha

via elliotf/mocha-mongoose · GitHub.

Test helpers for using mongoose with mocha.

See the example spec (copied below) for more details.