Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Javascript Testing with Jasmine

jcenturion
November 14, 2011

Javascript Testing with Jasmine

This is a summary about Jasmine's features.

jcenturion

November 14, 2011
Tweet

Other Decks in Programming

Transcript

  1. What is jasmine? Jasmine is a behavior-driven development framework for

    testing your JavaScript code. Saturday, November 12, 11
  2. Advantages • It does not depend on any other JavaScript

    frameworks • It has a clean, obvious syntax • It can be run anywhere you can execute JavaScript: • a static web page • a continuous integration environment • server-side environments like Node.js Saturday, November 12, 11
  3. Features • Suites and specs • Matchers • Before and

    After • Spies • Async Specs Saturday, November 12, 11
  4. Matchers • expect(x).toEqual(y); • expect(x).toBe(y); • expect(x).toMatch(pattern); • expect(x).toBeDefined(); •

    expect(x).toBeUndefined(); • expect(x).toBeNull(); • expect(x).toBeTruthy(); • expect(x).toBeFalsy(); • expect(x).toContain(y); • expect(x).toBeLessThan(y); • expect(x).toBeGreaterThan(y); • expect(fn).toThrow(e); toBeLessThan: function(expected) { return this.actual < expected; }; Saturday, November 12, 11
  5. Before and After describe('some suite', function () { var suiteWideFoo;

    beforeEach(function () { suiteWideFoo = 1; }); afterEach(function () { suiteWideFoo = 0; }); it('should equal bar', function () { expect(suiteWideFoo).toEqual(1); }); }); Saturday, November 12, 11
  6. Spies • spyOn(x, 'method').andCallThrough() • spyOn(x, 'method').andReturn(arguments) • spyOn(x, 'method').andThrow(exception)

    • spyOn(x, 'method').andCallFake(function) Jasmine integrates 'spies' that permit many spying, mocking, and faking behaviors. A 'spy' replaces the function it is spying on. Saturday, November 12, 11
  7. Jasmine & Ruby https://github.com/pivotal/jasmine/wiki/A-ruby-project $ gem install jasmine $ jasmine

    init $ rake jasmine:ci https://github.com/netzpirat/guard-jasmine group :development, :test do gem 'guard-jasmine' end https://github.com/bradphelan/jasminerice Jasminerice removes any excuse YOU have for not testing your out of control sprawl of CoffeeScript files. Saturday, November 12, 11