Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.
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          ...
Crosscheck                                  JSSpec
                    RhinoUnit

                     Test.More          ...
@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']
...
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...
Fixtures
fixtures/storyboard.html:
Stubbing

person.stub('age').and_return(22)
Mocking
mock_request()
Thank you!
JSpec - A Javascript Unit Testing Framework
JSpec - A Javascript Unit Testing Framework
JSpec - A Javascript Unit Testing Framework
JSpec - A Javascript Unit Testing Framework
JSpec - A Javascript Unit Testing Framework
JSpec - A Javascript Unit Testing Framework
JSpec - A Javascript Unit Testing Framework
JSpec - A Javascript Unit Testing Framework
JSpec - A Javascript Unit Testing Framework
JSpec - A Javascript Unit Testing Framework
JSpec - A Javascript Unit Testing Framework
JSpec - A Javascript Unit Testing Framework
JSpec - A Javascript Unit Testing Framework
Nächste SlideShare
Wird geladen in …5
×

JSpec - A Javascript Unit Testing Framework

5.332 Aufrufe

Veröffentlicht am

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.

Veröffentlicht in: Technologie

JSpec - A Javascript Unit Testing Framework

  1. 1. JSpec A JavaScript Testing Framework
  2. 2. About me
  3. 3. About me Lena Herrmann Ruby, Javascript, CouchDB
  4. 4. About me Lena Herrmann Ruby, Javascript, CouchDB http://lenaherrmann.net @kilaulena
  5. 5. Upstream Agile GmbH http://upstre.am/
  6. 6. Unit Testing
  7. 7. Crosscheck JSSpec RhinoUnit Test.More jsUnity jsUnitTest J3Unit QUnit JSUnit DOH Test.Simple Jasmine JSTest TestCase JSNUnit screw-unit YUI Test
  8. 8. Crosscheck JSSpec RhinoUnit Test.More jsUnity jsUnitTest J3Unit QUnit JSUnit JSpec DOH Test.Simple Jasmine JSTest TestCase JSNUnit screw-unit YUI Test
  9. 9. @tjholowaychuk
  10. 10. What does it look like?
  11. 11. Installation
  12. 12. Download tar from http://github.com/visionmedia/jspec/downloads
  13. 13. Download tar from http://github.com/visionmedia/jspec/downloads or $ git clone git://github.com/visionmedia/jspec.git
  14. 14. $ sudo gem install jspec
  15. 15. $ sudo gem install jspec $ jspec init --rails
  16. 16. Run
  17. 17. $ jspec run --rhino
  18. 18. $ jspec run --browsers ff,safari --server
  19. 19. Grammar Assertions
  20. 20. Grammar Assertions 'hello'.should.eql('hello') 'hello'.should.eql 'hello'
  21. 21. Grammar Functions
  22. 22. Grammar Functions -{ throw 'foo' }.should.throw_error 'foo'
  23. 23. Matchers be, eql, equal
  24. 24. 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']
  25. 25. Matchers be_a, be_an
  26. 26. Matchers be_a, be_an ['im', 'an', 'array'].should.be_an Array 'im a string'.should.be_a String
  27. 27. Matchers have_length
  28. 28. Matchers have_length ['cookies', 'ice cream'].length.should.eql 2 ['cookies', 'ice cream'].should.have_length 2
  29. 29. Matchers include
  30. 30. Matchers include ['cookies', 'apples'].should.include 'apples' ['cookies', 'apples'].should.not.include 'bread'
  31. 31. Matchers have_property
  32. 32. Matchers have_property { name: 'lena' }.should.have_property 'name' { name: 'lena' }.should.have_property 'name', 'lena'
  33. 33. Matchers jQuery
  34. 34. Matchers jQuery $('form#login .agree').should.not.be_clicked
  35. 35. Matchers jQuery $('form#login .agree').should.not.be_clicked $('form').should.have_id 'login'
  36. 36. 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 ...........
  37. 37. Fixtures
  38. 38. fixtures/storyboard.html:
  39. 39. Stubbing person.stub('age').and_return(22)
  40. 40. Mocking mock_request()
  41. 41. Thank you!

×