JavaScript Testing   With Mocha and Chai
JavaScript Test Frameworks•   QUnit•   Mocha•   YUI Test•   Jasmine•   JSUnit       •   CrosscheckJ3Unit JSNUnit JSSpec   ...
Choosing a framework•   Client side?•   Server side?•   Well maintained?•   Well documented?•   Integration with CI
Mocha
Mocha•   Feature Rich•   Runs on node + the browser•   Simplifies async testing•   Growl notifications•   Choose your own ...
Chai•   BBD / TDD•   For node + the browser•   Three assertion styles    •   should - foo.should.be.a(‘string’)    •   exp...
Getting started•   Requires node•   Requires npm•   npm install -g mocha•   npm install -g chai
Setup•   Expects tests to be in <project_root>/test•   Allows of per project options file:    •   mocha.opts•   To run tes...
First testdescribe(Array, function(){  describe(#indexOf(), function(){    it(should return -1 when the value is not prese...
Hooks•   before()•   after()•   beforeEach()•   afterEach()
Modifying Test Cases•   Pending tests - no callback•   Exclusive tests - append .only•   Inclusive tests - append .skip
Other features•   mocha --reports•   mocha --watch•   mocha --growl•   mocha --compilers•   Interface support for: TDD, BD...
CoffeeScript•   mocha --compilers coffee:coffee-script             describe Task instance, ->               task1 = task2 ...
Fin
Upcoming SlideShare
Loading in...5
×

JavaScript Testing: Mocha + Chai

3,764

Published on

Introduction to Mocha with Chai for TDD/BDD with JavaScript

Published in: Technology
0 Comments
7 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,764
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
43
Comments
0
Likes
7
Embeds 0
No embeds

No notes for slide

JavaScript Testing: Mocha + Chai

  1. 1. JavaScript Testing With Mocha and Chai
  2. 2. JavaScript Test Frameworks• QUnit• Mocha• YUI Test• Jasmine• JSUnit • CrosscheckJ3Unit JSNUnit JSSpec UnitTestingJSpec screw-unit• Suitest Test.SimpleRhinoUnit Buster.JS• Sinon.js• DOH• Enhance JS• RhUnit
  3. 3. Choosing a framework• Client side?• Server side?• Well maintained?• Well documented?• Integration with CI
  4. 4. Mocha
  5. 5. Mocha• Feature Rich• Runs on node + the browser• Simplifies async testing• Growl notifications• Choose your own assertion library
  6. 6. Chai• BBD / TDD• For node + the browser• Three assertion styles • should - foo.should.be.a(‘string’) • expect - expect(foo).to.be.a(‘string’) • assert - assert.typeOf(foo, ‘string’)
  7. 7. Getting started• Requires node• Requires npm• npm install -g mocha• npm install -g chai
  8. 8. Setup• Expects tests to be in <project_root>/test• Allows of per project options file: • mocha.opts• To run test: • mocha
  9. 9. First testdescribe(Array, function(){ describe(#indexOf(), function(){ it(should return -1 when the value is not present, function(){ [1,2,3].indexOf(5).should.equal(-1); [1,2,3].indexOf(0).should.equal(-1); }) })})
  10. 10. Hooks• before()• after()• beforeEach()• afterEach()
  11. 11. Modifying Test Cases• Pending tests - no callback• Exclusive tests - append .only• Inclusive tests - append .skip
  12. 12. Other features• mocha --reports• mocha --watch• mocha --growl• mocha --compilers• Interface support for: TDD, BDD + QUnit
  13. 13. CoffeeScript• mocha --compilers coffee:coffee-script describe Task instance, -> task1 = task2 = null it should have a name, -> task1 = new Task feed the cat task1.name.should.equal feed the cat
  14. 14. Fin
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×