varvows=require('vows'),assert=require('assert');varstory=require('../lib/story');varUUID_PATTERN=/[0-9a-f]{8}\-[0-9a-f]{4}\-[0-9a-f]{4}\-[0-9a-f]{4}\-[0-9a-f]{8}/;vows.describe('Story').addBatch({'A new story':{topic:function(){returnstory.create({name:"As a developer, I want to known NodeJS so that i increase my knowledge",description:"By learning NodeJS, the developer will be able to undestand its success",complexity:7,business_value:120});},'should return an instance of Story':function(st){assert.instanceOf(st,story.Story);},'should have the specified name':function(story){assert.equal(story.name(),'As a developer, I want to known NodeJS so that i increase my knowledge');},'should have the specified description':function(story){assert.equal(story.description(),'By learning NodeJS, the developer will be able to undestand its success');},'should have the specified complexity':function(story){assert.equal(story.complexity(),7);},'should have the specified business value':function(story){assert.equal(story.business_value(),120);},'should have a generated uuid':function(story){assert.equal(UUID_PATTERN.test(story.uuid()),true);}}}).export(module);// Export the Suite

Créons aussi notre premier test unitaire:
test/story_test.js

varstory=require("../lib/story");exports["create return a new story"]=function(test){varst=story.create("mccallum");test.ok(stinstanceofstory.Story);test.done();};

varstory=require("../lib/story");varUUID_PATTERN=/[0-9a-f]{8}\-[0-9a-f]{4}\-[0-9a-f]{4}\-[0-9a-f]{4}\-[0-9a-f]{8}/;exports["create return a new story"]=function(test){varst=story.create("mccallum");test.ok(stinstanceofstory.Story);test.done();};exports["create return a new story with the given name"]=function(test){varst=story.create({name:"mccallum"});test.equal(st.name(),"mccallum");test.done();};exports["create return a new story a generated uuid"]=function(test){varst=story.create({name:"mccallum"});test.ok(UUID_PATTERN.test(st.uuid()));test.done();};exports["a new story must have an `events` method to retrieve its history"]=function(test){varst=story.create({name:"mccallum"});varevents=st.events();test.ok(eventsinstanceofArray);test.done();};exports["a new story must have a single `event` in its history"]=function(test){varst=story.create({name:"mccallum"});varevents=st.events();test.ok(eventsinstanceofArray);test.equal(events.length,1);test.done();};exports["a new story must have a single `event` in its history of type 'story_created'"]=function(test){varst=story.create({name:"mccallum"});varevents=st.events();test.ok(eventsinstanceofArray);test.equal(events.length,1);test.equal(events[0].event_type(),"story_created");test.done();};

exports["a new story must have a 'name' and a 'project_id' specified"]=function(test){test.throws(function(){story.create({});});test.done();}exports["a new story must have a 'project_id' specified"]=function(test){test.throws(function(){story.create({name:"mccallum"});});test.done();}exports["a new story must have a 'name' specified"]=function(test){test.throws(function(){story.create({project_id:"mccallum"});});test.done();}

'Story':{topic:function(){returnstory.create({project_id:"cafebabe-3550",name:"As a developer, I want to known NodeJS so that i increase my knowledge",});},'can be improved by adding comment on it':function(story){varCONTENT="NodeJS looks promising, not only for application but also as a tool to test and learn javascipt";story.add_comment(CONTENT);varlast_event=story.last_event();assert.equal(last_event.event_type(),"story_comment_added");assert.equal(last_event.content(),CONTENT);}}