JSpec - A Javascript Unit Testing Framework
Upcoming SlideShare
Loading in...5
×
 

JSpec - A Javascript Unit Testing Framework

on

  • 5,787 views

JSpec is a great framework for writing unit tests for your Javascript code. I show you why I chose it and how you install and use it.

JSpec is a great framework for writing unit tests for your Javascript code. I show you why I chose it and how you install and use it.

Statistics

Views

Total Views
5,787
Views on SlideShare
5,733
Embed Views
54

Actions

Likes
4
Downloads
64
Comments
3

2 Embeds 54

http://www.slideshare.net 43
http://twiki.corp.yahoo.com 11

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

13 of 3 Post a comment

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • Oops! This slide did not convert properly hence cannot be displayed. Slide at 13/54, 15/54, 16/54 etc.
    Are you sure you want to
    Your message goes here
    Processing…
  • Excellent introduction. Thank you!
    Are you sure you want to
    Your message goes here
    Processing…
  • introduction
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • We take TDD very seriously <br /> Working on my thesis there: <br />
  • My thesis: an outliner, a couchapp <br /> Have a project in mind where Javascript is the main language <br /> Application is served by CouchDB - no other server, other language involved <br />
  • Not about full stack integration test <br /> <br />
  • Tiny (15 kb compressed, 1600-ish LOC) <br /> <br />
  • project: 1 and a half years old, more than 30 forks on git <br /> in active development <br />
  • <br />
  • no parentheses, "function" expressions, curly brackets <br /> Cascading before/after hooks -- Nested describe blocks (DRY, organization) <br /> Textmate bundle, Syntax hightlighting <br />
  • grammar-less alternative <br />
  • <br />
  • Two ways to install jspec: <br /> 1st, when project should come without prerequisites <br /> <br />
  • <br />
  • Just drop the files into your project. <br />
  • 2nd: - when to be used with CI <br /> - when you DON&apos;T want to test the DOM <br /> Rails command copies a jspec template folder into your project <br />
  • <br />
  • Two ways to run the tests <br />
  • Open the html file in any browser. <br />
  • Also show only failing tests <br />
  • Not so nice: instead of test groups, you have to put tests into different files <br />
  • Java implementation of Javascript (like Spidermonkey is in C) <br />
  • <br />
  • When you have the gem already installed: <br /> opens browsers in the background, report back to console <br />
  • <br />
  • <br />
  • <br />
  • equal = object identity === <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • there&apos;s many more <br />
  • there&apos;s many more <br />
  • there&apos;s many more <br />
  • sometimes you want to test DOM manipulation <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • Mocking: <br /> - Possible to include Mocking frameworks <br /> - or as its JS, just override the methods <br />
  • <br />

JSpec - A Javascript Unit Testing Framework JSpec - A Javascript Unit Testing Framework Presentation Transcript

  • JSpec A JavaScript Testing Framework
  • About me
  • About me Lena Herrmann Ruby, Javascript, CouchDB
  • About me Lena Herrmann Ruby, Javascript, CouchDB http://lenaherrmann.net @kilaulena
  • Upstream Agile GmbH http://upstre.am/
  • Unit Testing
  • Crosscheck JSSpec RhinoUnit Test.More jsUnity jsUnitTest J3Unit QUnit JSUnit DOH Test.Simple Jasmine JSTest TestCase JSNUnit screw-unit YUI Test
  • Crosscheck JSSpec RhinoUnit Test.More jsUnity jsUnitTest J3Unit QUnit JSUnit JSpec DOH Test.Simple Jasmine JSTest TestCase JSNUnit screw-unit YUI Test
  • @tjholowaychuk
  • What does it look like?
  • Installation
  • Download tar from http://github.com/visionmedia/jspec/downloads
  • Download tar from http://github.com/visionmedia/jspec/downloads or $ git clone git://github.com/visionmedia/jspec.git
  • $ sudo gem install jspec
  • $ sudo gem install jspec $ jspec init --rails
  • Run
  • $ jspec run --rhino
  • $ jspec run --browsers ff,safari --server
  • Grammar Assertions
  • Grammar Assertions 'hello'.should.eql('hello') 'hello'.should.eql 'hello'
  • Grammar Functions
  • Grammar Functions -{ throw 'foo' }.should.throw_error 'foo'
  • Matchers be, eql, equal
  • Matchers be, eql, equal true.should.be true 2.should.eql 2 2.should.eql '2' ['foo', 'bar'].should.eql ['foo', 'bar'] ['foo', 'bar'].should.not.equal ['foo', 'bar']
  • Matchers be_a, be_an
  • Matchers be_a, be_an ['im', 'an', 'array'].should.be_an Array 'im a string'.should.be_a String
  • Matchers have_length
  • Matchers have_length ['cookies', 'ice cream'].length.should.eql 2 ['cookies', 'ice cream'].should.have_length 2
  • Matchers include
  • Matchers include ['cookies', 'apples'].should.include 'apples' ['cookies', 'apples'].should.not.include 'bread'
  • Matchers have_property
  • Matchers have_property { name: 'lena' }.should.have_property 'name' { name: 'lena' }.should.have_property 'name', 'lena'
  • Matchers jQuery
  • Matchers jQuery $('form#login .agree').should.not.be_clicked
  • Matchers jQuery $('form#login .agree').should.not.be_clicked $('form').should.have_id 'login'
  • Matchers jQuery $('form#login .agree').should.not.be_clicked $('form').should.have_id 'login' have_tag, have_child, have_text, have_class, be_visible, be_selected, have_alt ...........
  • Fixtures
  • fixtures/storyboard.html:
  • Stubbing person.stub('age').and_return(22)
  • Mocking mock_request()
  • Thank you!