Advanced Jasmine

Preview:

DESCRIPTION

Topics in intermediate/early-advaned Jasmine testing for client-side JavaScript web applications. Source code, test specs, and harnesses available here: https://github.com/jbellsey/dbc-jasmine

Citation preview

Advanced Testing With Jasmine

Jeff Bellsey

jbellsey@gmail.com

http://futureground.net

https://github.com/ jbellsey/dbc-jasmine

SPIES1

SPIES

Control

Objectives

Prevent method under observation from invoking helpers (expensive, side-effect-prone)

Ensure those helpers are actually being called properly

Tracking

Isolation

Replace operations with simulations to test how our method responds

SPIES

SPIES

Useful spy methods

SPIES

TIMERS2

TIMERS

TIMERS

What about requestAnimationFrame?

Some testing support is best provided outside of Jasmine

$.Velocity.mock = true; Velocity.js

TimelineLite.timeScale()Greensock

TIMERS

AJAX2Bonus!

Most of the time…

YOU DON’T.

Angular.js => angular-mocks jQuery => mockJax Backbone => backbone-faux-server

Use library mocks

Integration tests Karma Selenium PhantomJS

But once in a while…

AJAX

AJAX

AJAX

DOM3

Jasmine-jQuery plugin

DOM

Jasmine-jQuery plugin

DOM

Has tons of great matchers

CUSTOM MATCHERS4

CUSTOM MATCHERS

CUSTOM MATCHERS

Jeff Bellsey

jbellsey@gmail.com

http://futureground.net

https://github.com/jbellsey/dbc-jasmine