2012-02-19 5 views
20

私はnodejsプロジェクトを開始しており、MochaとZombiejsでBDDを行いたいと考えています。残念ながら、私はその文の中のあらゆる流行語に慣れています。私はMochaとZombiejsのテストをうまく動かすことができますが、私は2つを統合するようには見えません - Zombiejsテストを実行するためにMochaを使用することは可能でしょうか?MochaとZombieJS

「hello world」を探してみてください。しかし、チュートリアル/例はさらに優れています。

ありがとうございます!

+0

私の答えは、あなたが念頭に置いていたものでしたか? – Industrial

+0

うん、それは私が望んだことだ。ありがとう! – Joel

答えて

36

すでに指示に従って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) 

注:タイムアウトによりテストが失敗し続ける場合は、mocha 'st -t引数を使用してビットを設定してください。詳細は、mochaのドキュメントを参照してください。

+0

この問題のためnodejs 0.10.xxと一緒に使用するとゾンビが失敗することに注意してくださいhttps://github.com/assaf/zombie/issues/487 歓声 –

+4

問題は修正されているようです。 –

7

私は、非同期テスト、良い習慣( 'before()'、 'after()'、TDD、...)に関する重要な問題点を説明し、現実の例で説明しました。

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

+1

この投稿を移動したことがありますか? – Alex

+0

ああ、本当にこれも読んでみたかった!あなたはそれをポストヘブンに移したとは思わないでしょうか? –

+0

ちょっと、ゾンビ糸。記事は移動しました:http://redotheweb.com/2013/01/15/functional-testing-for-nodejs-using-mocha-and-zombie-js.html –

-1

は、MicrosoftのVisual Studioを使用している場合は、ロブ・アシュトンのZombifyを見てみたいことがあります。 JavaScriptやCoffeeScriptでテストケースを書くことができるように、すべてが合理的に統合されています。ところで、CoffeeScriptを学ぶことは1時間ほどかかるでしょう。それは毎分の価値があります。

1

受け入れテストではcucumber-jsを使用し、ページでは "unit"テストではmochaを使用する場合は、cuked-zombie(広告には申し訳ありません)を使用できます。

次に、このようなあなたのユニットテストでゾンビとのモカを使用

`/* globals __dirname */ 
var os = require('os'); 
var path = require('path'); 

module.exports = { 
    cli: null, 
    domain: 'addorange-macbook': 'my-testing-domain.com', 
    debug: false 
}; 

をgithubの上のreadmeに記述のようにそれをインストールしますが、あなたの世界の設定が世界的にあるconfig.jsというファイルに配置します。

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; 
     }); 
関連する問題