Created: 2008-06-24 00:45
Updated: 2016-05-08 10:01

Latte: A mocking library for JavaScript

Latte is a really simple class to aid in detecting whether methods are invoked or not when you call other methods on a given object.

Download the repo and run example.html to see it in action, written for UnitTest (scriptaculous testing library).

Say you have a class:

var Barista = Class.create({
  askForSugar: function(){}

And you want to verify that when you call the Barista#makeCoffee method, the Barista#askForSugar method should be called.

You include latte.js in your page and then you write something like this:

var mock = new Latte(Barista, 'askForSugar');
var b = new Barista();
console.log('Barista#askForSugar not invoked yet, right?' + mock.notInvoked('askForSugar'));
console.log('Barista#askForSugar was invoked now, right? ' + mock.wasInvoked('askForSugar'));

Written to depend on prototype

The name Latte is a homage to Mocha, a really great mocking and stubbing library for Ruby.

Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more