but seriously...
describe("User Registration", function() {
describe("While validating the registration info", function() {
it("should make sure the email address is valid", function() {
// assert that email is valid
});
it("should verify the email doesn't already exist", function() {
// assert that email doesn't exist
}); ...
});
describe("While creating the user's database record", function() {
it("should save successfully in the database", function() {
// assert the database record was saved
}); ...
});
});
Describe User Registration While validating the registration info - it should make sure the email address is valid - it should verify the email doesn't already exist ... While creating the user's database record - it should save successfully in the database ...
npm install mocha -g
> cd my-node-project
> mkdir test
> mocha init
To run a "local" install of mocha:
> ./node_modules/.bin/mocha
Node modules that have an executable get a link to that command in the node_modules/.bin directory.
var assert = require('assert'); // built-in node lib
describe("My Mocha Smoke test", function() {
it("should add 2 numbers", function() {
assert.equal(2 + 2, 4, "2 + 2 = 4, dang it!");
});
});
test/tests.js
> mocha
․ 1 passing (3ms)
> mocha --reporter spec
My Mocha Smoke test ✓ should add 2 numbers 1 passing (4ms)
> mocha -w
> mocha -h
--watch
--color
--reporter spec
--growl
--timeout 5000
--slow 1000
--recursive
var assert = require('assert'); // built-in node lib
describe("My Mocha Smoke test", function() {
it("should add 2 numbers", function() {
assert.equal(2 + 2, 4, "2 + 2 = 4, dang it!");
});
it.only("should subtract 2 numbers", function(){
assert.equal(2 - 2, 0, "2 - 2 = 0, thanks");
});
});
it("should wait 1 second before finishing", function(done){
setTimeout(function(){
// la dee dah! We can do something here I guess.
assert.ok(true, "I love mocha in the morning");
// ok, we're done, let mocha know.
done();
}, 1000);
});