Currently, I am attempting to perform Unit Testing using the Jasmine framework with a websocket (jasmine-2.4.1 version).
While the send
function for the websocket is working correctly, there seems to be an issue with the onmessage
function.
The returned value is showing up as undefined.
Below is the code snippet that I am working with:
var ws;
beforeEach(function() {
ws = new WebSocket("ws://myaddress:port");
});
describe("Module Test", function() {
it("first test", function (done) {
// Send data to the 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...
};
// The server returns a result value of 'true', however, when trying to access it here, it shows as undefined...
expect(result).toBe(true);
done();
});
});