2017-09-17 1 views
1

私はjasmine-nodeでFrisyを使ってMeteor APIをテストします。jasmine-node付きFrisby JSの子供テストは無視されました

私はチャットアプリケーションでディスカッションの削除をテストしたいと思います。そのためには、チャットで新しいディスカッションを作成し、ディスカッションにメッセージを追加する必要があります。

2番目の.then()メソッドの後に置くとテストが失敗することに気付きました。 3番目の.then()の後にも失敗します。ただし、最初の.then()メソッドの後で正しく動作します。

明示的にテストが失敗したコード例expect(false).toBe(true);

var frisby = require('frisby'); 
describe("chat update", function() { 
    it("message added", function(done) { 
    frisby.post('http://localhost:3000/api/chat', { 
     name: "remove" 
    }) 
    .then(function (res) { 
     let id = res._body.id; 
     expect(false).toBe(true); // (1) it fails the test 
     frisby.post('http://localhost:3000/api/chat/'+id+'/addmessage', 
     { 
      auteur: "Samuel", 
      message: "My message" 
     } 
    ) 
     .then(function (res) { 
     expect(false).toBe(true); // (2) Without (1) it's ignored by frisby 
     frisby.post('http://localhost:3000/api/chat/remove', 
      {id: id} 
     ) 
     .then(function (res) { 
      expect(false).toBe(true); // (3) Without (1) it's ignored by frisby 
     }) 
     }); 
    }) 
    .done(done); 
    }) 
}); 

私がテストを実行する場合、それは(偽).toBe(true)を期待するのおかげで失敗します。 //(1)テストに失敗しました行。 この行を削除すると、テストが実行され、ジャスミンが正しい行であることを確認します。

あなたは(2)と(3)のテストを無視しない方法を知っていますか?

+0

古いバージョンのFrisbyまたはそれ以降のバージョンを使用していますか? "古い"バージョンはジャスミンノードを使用し、新しいバージョンはJestを使用するため、私は尋ねます。 –

+0

新しいものを使用します。私は解決策を見つけ、それを答えにしました。私はリターン演算子を忘れてしまった。ありがとう。 – jedema

答えて

1

最終的に、解決策が見つかりました。

var frisby = require('frisby'); 
describe("chat update", function() { 
    it("message added", function(done) { 
    frisby.post('http://localhost:3000/api/chat', { 
     name: "remove" 
    }) 
    .then(function (res) { 
     let id = res._body.id; 
     return frisby.post('http://localhost:3000/api/chat/'+id+'/addmessage', 
     { 
      auteur: "Samuel", 
      message: "My message" 
     } 
    ) 
     .then(function (res) { 
     return frisby.post('http://localhost:3000/api/chat/remove', 
      {id: id} 
     ) 
     .then(function (res) { 
      expect(false).toBe(true); // Will fail the test 
     }) 
     }); 
    }) 
    .done(done); 
    }) 
}); 

あなたはfrisby.post()リターン事業者に気付くことがあります。 それは私がリターンに次のコードのように(最初のものを除く)のすべてのfrisbyアクションを忘れてしまったためです。 私はそれが助けてくれることを願っています!

関連する問題