jasmine-precondition

In January, 2015 I published the jasmine-precondition project on GitHub. This project aims to implement a Jasmine instruction to ease setting up asynchronous pre-conditions before, during and after tests.

Motivation

Since Jasmine 2.0, the runs, waits, and waitsFor methods have been removed in favor of allowing functions run as part of the spec to receive and invoke a done callback. This new approach is described at Upgrading Jasmine - Asynchronous Specs.

The done callback works great for asynchronous features with a callback (such as AJAX, jQuery animations or anything else with promises). However, there are yet other asynchronous features that will complete on their own and would be using waitsFor before Jasmine 2.0, like rendering Google Maps, images or anything else that can change both the DOM and the CSSOM.

While it is utterly possible to re-implement waitsFor I believe that Jasmine 2.0 direction is more towards stepping away from this idea and instead taking more advantage of done callbacks, like putting one it block as a pre-condition for another.

Thus, the preCondition instruction defined here will simply poll a given conditional function at a certain time interval, and once its condition is met the callback done will be fired off.

Current status

To the date, its version 0.1.0 can be used either standalone and through node.js, available on NPM.

Travis CI status:

Usage

preCondition(condition, done, interval);

where:

  • condition: a conditional function that shall only return true when the condition you are expecting for is met.
  • done: the done callback from beforeEach, it or afterEach must be passed here.
  • interval (optional): a time interval in milliseconds between two condition executions. Default is 100.

Example

Jasmine Testing for Models and Views + Directory structure on modularized apps

On November 13th, 2014 I hosted the Backbone.js Hackers meetup in San Francisco, CA at Macy’s.com.

Thanks Avenue Code for sponsoring the food and drinks and Yulia Kukuyuk from Macy’s.com for arranging the venue!

On this meetup we had 2 talks:

1) David Beck - Modularized Backbone Apps Part 2: Directory Structure

This talk is about modularization of the front end into encapsulated, reusable packages, via development of tools such as cartero, backbone.subviews, and backbone.courier.

2) Brenda Jin - Jasmine Testing for Backbone.js Models and Views

This session will cover a breakdown of how to approach Jasmine testing for Backbone.js Models and Views, how Jasmine testing works with instantiating new Models and Views, and how to trigger and test custom events and their callbacks. Her slide deck is also available.

Check out Jasmine Testing for Models and Views + Directory structure on modularized apps.

You can also watch the Video.