Testing Backbone applications with Jasmine and Sinon

Testing Backbone applications with Jasmine and Sinon


# Sinon.JS

Sinon.JS is a library that provides fake objects – spies, stubs and mocks 

* Performance - real DOM manipulation, reliance on timed behaviour and network activity slows tests down
* Isolation - unit tests should focus on as small a piece of functionality as possible, and be de-coupled from unreliable or slow dependencies

# Spies

Spies are functions that keep track of how and often they were called, and what values were returned. This is phenomenally useful in asynchronous and event-driven applications as you can send a spy function off to keep track of what’s going on inside your methods, even if those methods are anonymous or closed off from direct inspection.

Spies can be ‘anonymous’ or can spy on existing functions.

An anonymous spy is just an empty function with spying features that can be sent off to record how it was used. Like a real spy being sent behind enemy lines with a microphone attached to it’s chest, the method under test is none the wiser. Here is an example of a spy testing a simple 

# fake server sinon.fakeServer.creat

0 pensamientos:

Post a Comment

feedback!