3
私はe2eテストのためにProtracotrを使用しています。分度器:HTTP応答テスト
分度器でHTTPからの応答をテストしたいと思います。 基本的に:
- NodeJSサーバーを実行しています。私は、彼らが
正しければ、これらのデータに
var http = require('http');
describe("Some test", function() {
function httpGet(siteUrl) {
http.get(siteUrl, function(response) {
response.setEncoding('utf8');
response.on("data", function(chunk) {
bodyString += chunk;
});
response.on('end', function() {
defer.fulfill({
bodyString: bodyString
});
});
}).on('error', function(e) {
defer.reject("Got http.get error: " + e.message);
});
return defer.promise;
}
it('Test case', function(){
httpGet("http://localhost:3333/path/1/10").then(function(result) {
var json_data = JSON.parse(result.bodyString);
for (var i = 0; i < json_data.length; ++i) {
console.log("label: " + json_data[i].label);
expect(json_data[i].label).toEqual('abc');
}
});
});
});
私はにconsole.logで解析された応答メッセージの素敵を見ることができますが、私は何をテストすることはできないんだけど、私の試験結果はです:
Finished in 0.019 seconds
1 test, 0 assertions, 0 failures
label: Text1
label: Text2
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 passed
Process finished with exit code 0
コンソールログは書き留めですテストの終了後、アサーションは行われていません。
何か助けてください、それらのレスポンスを(JSON形式で)分度器のサーバーからテストする方法はありますか?
また、元の質問にも変更があります(審査中)。あなたの最初の質問は分度器に関するものでした。しかし、私はあなたがJasmineをテストフレームワークとして探していると信じています。 – cnishina
コメントありがとうございます!私はdone()を呼び出そうとしていますが、うまくいきません.ReferenceError:doneは定義されていません。エラーです。また、 'TypeError:httpGet(...)。then(...)。catchは関数ではありません' – mcPetrson
うん。良い点...コールバックのためです。太い矢を使うべきです。私の答えを更新させてください。 – cnishina