Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Mocha Testing

Mocha Testing

  • Login to see the comments

Mocha Testing

  1. 1. JavaScript Testing With Mocha and Chai
  2. 2. What we have? • QUnit • Mocha • YUITest • Jasmine • JSUnit • Suitest • Sinon.js • DOH • Enhance JS • RhUnit • ….
  3. 3. Why Mocha? • Client side • Server side • Well maintained • Well documented • Integration with CI • We can choose desired assertion library
  4. 4. Mocha
  5. 5. Mocha • Feature Rich • Runs on node + the browser • Simplifies async testing • Supports TDD/BDD • Choose any Mocking library • File watcher support
  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 test describe('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. Hooks describe('Array', function() { before(function() { }); after(function(){ }); })
  12. 12. Thanks!

×