2. ABOUT
Rubyist / JavaScripter
Yeoman Team Member / @keralarb /
@keralajs
Works at
Blog at
Twitter/Github -
Google+:
@whatznear
blog.revathskumar.com
@revathskumar
+RevathSKumar
3. AGENDA
Mocha Features
BDD/TDD syntax
Chai assert library
Testing asynchronous code
Testing in Node.js and Browser
Grunt and gulp tasks
7. MOCHA: FEATURES
Runs on Node.js/Browser
Supports BDD/TDD
Choose any assertion library
Choose any Mocking library
Async and promise support
Highlights slow tests
File watcher support
Optionally run tests that match a regexp
8. MOCHA: TDD
suite('Calculator', function () {
suite('Add', function(){
test("using both positive numbers", function(){
// test assertion
});
test("using both negative numbers", function(){
// test assertion
});
});
});
9. MOCHA: SETUP & TEARDOWN
suite('Calculator', function () {
setup(function(){
// runs before test
});
//test("add using both positive numbers", function(){
// test assertion
//});
teardown(function(){
// runs after tests
});
});
10. MOCHA: BDD
describe('Calculator', function () {
describe('add', function () {
it('using both positive numbers',function(){
// test assertion
});
it('using both negative numbers',function(){
// test assertion
});
});
});
11. MOCHA: BEFORE & AFTER
describe('Calculator', function () {
before(function(){
})
after(function(){
})
});
beforeEach
afterEach
24. PENDING TESTS
Mark as pending
test without callback
suite("add", function(){
test("two positive");
});
25. EXCLUSIVE TESTS
Run only specific test/suite
similar to grep
suite("add", function(){
test.only("two positive", function(){
assert(Calc.add(1,3), 4);
});
test("positive and negaive", function(done){
assert(Calc.add(-5, 4), -1);
})
});