KEMBAR78
JSpec - A Javascript Unit Testing Framework | KEY
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!

JSpec - A Javascript Unit Testing Framework

Editor's Notes

  • #5 We take TDD very seriously Working on my thesis there:
  • #6 My thesis: an outliner, a couchapp Have a project in mind where Javascript is the main language Application is served by CouchDB - no other server, other language involved
  • #7 Not about full stack integration test
  • #8 Tiny (15 kb compressed, 1600-ish LOC)
  • #9 project: 1 and a half years old, more than 30 forks on git in active development
  • #11 no parentheses, "function" expressions, curly brackets Cascading before/after hooks -- Nested describe blocks (DRY, organization) Textmate bundle, Syntax hightlighting
  • #12 grammar-less alternative
  • #14 Two ways to install jspec: 1st, when project should come without prerequisites
  • #16 Just drop the files into your project.
  • #17 2nd: - when to be used with CI - when you DON'T want to test the DOM Rails command copies a jspec template folder into your project
  • #19 Two ways to run the tests
  • #20 Open the html file in any browser.
  • #21 Also show only failing tests
  • #22 Not so nice: instead of test groups, you have to put tests into different files
  • #23 Java implementation of Javascript (like Spidermonkey is in C)
  • #25 When you have the gem already installed: opens browsers in the background, report back to console
  • #29 equal = object identity ===
  • #34 there's many more
  • #35 there's many more
  • #36 there's many more
  • #37 sometimes you want to test DOM manipulation
  • #42 Mocking: - Possible to include Mocking frameworks - or as its JS, just override the methods