摩卡和僵尸

我正在开始一个nodejs项目,并想与Mocha和Zombiejs一起做BDD。 不幸的是,我对这句话中的每一个stream行语都是新的。 我可以让Mocha和Zombiejs正常运行testing,但是我似乎无法整合这两者 – 是否可以使用Mocha来运行Zombiejstesting,如果是这样,那将如何呢?

只是寻找“你好世界”让我开始,但一个教程/例子会更好。

谢谢!

假设你已经按照说明安装了mochazombieexpect.js ,这应该适合你:

 // Put below in a file in your *test* folder, ie: test/sampletest.js: var expect = require('expect.js'), Browser = require('zombie'), browser = new Browser(); describe('Loads pages', function(){ it('Google.com', function(done){ browser.visit("http://www.google.com", function () { expect(browser.text("title")).to.equal('Google'); done(); }); }); }); 

那么你应该可以从根应用程序文件夹运行mocha命令:

 # mocha -R spec Loads pages ✓ Google.com (873ms) ✔ 1 tests complete (876ms) 

注意:如果你的testing由于超时而保持失败,通过使用-t参数有助于增加mocha的超时设置。 查看摩卡的文档了解完整的细节。

我写了一个冗长的回答,解释了关于asynchronoustesting,好的实践('before()','after()',TDD等)的重要问题,并用真实世界的例子来说明。

http://redotheweb.com/2013/01/15/functional-testing-for-nodejs-using-mocha-and-zombie-js.html

如果你想用你的验收testing和摩卡作为你的“单位”testing的黄瓜-js页面,你可以使用cuked僵尸 (抱歉的广告)。

像github上的自述文件中描述的那样安装它,但将你的世界configuration放在一个名为world-config.js的文件中

 `/* globals __dirname */ var os = require('os'); var path = require('path'); module.exports = { cli: null, domain: 'addorange-macbook': 'my-testing-domain.com', debug: false }; 

然后在你的unit testing中使用mocha与僵尸:

 var chai = require('chai'), expect = chai.expect; var cukedZombie = require('cuked-zombie'); describe('Apopintments', function() { describe('ArrangeFormModel', function() { before(function(done) { // execute once var that = this; cukedZombie.infectWorld(this, require('../world-config')); this.world = new this.World(done); // this inherits the whole world api to your test _.merge(this, this.world); }); describe("display", function() { before(function(done) { // executed once before all tests are run in the discribe display block var test = this; this.browser.authenticate().basic('maxmustermann', 'Ux394Ki'); this.visitPage('/someurl', function() { test.helper = function() { }; done(); }); }); it("something on the /someurl page is returned", function() { expect(this.browser.html()).not.to.be.empty; }); 

如果您正在使用Microsoft Visual Studio,则可能需要查看Rob Ashton的Zombify 。 一切都是可以接受的集成,所以你可以开始用JavaScript或CoffeeScript编写testing用例。 顺便说一下,学习CoffeeScript将会花费你一个小时,这是值得的每一分钟。