Mocha和ZombieJS [英] Mocha and ZombieJS
问题描述
我正在启动一个nodejs项目,并希望与Mocha和Zombiejs进行BDD.不幸的是,我对这句话中的每个流行词都是陌生的.我可以让Mocha和Zombiejs正常运行测试,但我似乎无法将两者集成在一起-是否可以使用Mocha来运行Zombiejs测试,如果可以,外观如何?
I'm starting a nodejs project and would like to do BDD with Mocha and Zombiejs. Unfortunately I'm new to just about every buzzword in that sentence. I can get Mocha and Zombiejs running tests fine, but I can't seem to integrate the two - is it possible to use Mocha to run Zombiejs tests, and if so, how would that look?
只是在寻找"hello world"来帮助我入门,但是教程/示例会更好.
Just looking for "hello world" to get me started, but a tutorial/example would be even better.
谢谢!
推荐答案
假设您已经安装了 mocha
, zombie
和 expect.js
根据说明,这应该对您有用:
Assuming you already have installed mocha
, zombie
and expect.js
according to instructions, this should work for you:
// 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
命令:
Then you should be able to run the mocha
command from your root application folder:
# mocha -R spec
Loads pages
✓ Google.com (873ms)
✔ 1 tests complete (876ms)
注意::如果由于超时而导致测试失败,则可以使用-t
参数来增加mocha
的超时设置.查看mocha的文档以获取完整的详细信息.
Note: If your tests keep failing due to timeouts, it helps to increase mocha
's timeout setting a bit by using the -t
argument. Check out mocha's documentation for complete details.
这篇关于Mocha和ZombieJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!