0
我試圖將UnitTest與websocket結合使用Jasmine框架。 (jasmine-2.4.1 ver。)如何在茉莉花框架中使用websocket?
websocket send
功能沒問題。但onmessage
函數有問題。
結果值未定義。
這裏是我的代碼:
var ws;
beforeEach(function() {
ws = new WebSocket("ws://myaddress:port");
});
describe("Module Test", function() {
it("first test", function (done) {
//send to server
ws.onopen = function(e) {
ws.send(JSON.stringify({"module":"test","func":"test_func"}));
};
var result;
ws.onmessage = function(e) {
result = JSON.parse(e.data.rsp);
console.log(result); // <- this result value is true...
};
//server return result value.. and... it is true.....
//but result value is undefiend....
expect(result).toBe(true);
done();
});
});
var結果值未被滿足。 所以,toBeTruthy()不起作用。 :( –
@SunghoPark道歉...我認爲你的onmessage函數是'真正的',這就是你的評論旁邊的說法,這就是爲什麼我認爲這是在檢索結果值之前斷言的簡單錯誤 – Shakespeare