Skip to content

Instantly share code, notes, and snippets.

@saml
Created June 25, 2020 19:28
Show Gist options
  • Save saml/ab310b0a73f703dcb4ac3d98a121dc54 to your computer and use it in GitHub Desktop.
Save saml/ab310b0a73f703dcb4ac3d98a121dc54 to your computer and use it in GitHub Desktop.
test("Can receive broadcast connection", async (done) => {
jest.setTimeout(500); // timeout quickly if done() isn't called.
let postResult = null;
// Need to set up message handler *before* making POST request.
ws.addEventListener("message", async (event) => {
try {
// When message arrives, we know POST request was sent. So, verify its result.
const resp = await postResult;
expect(resp.status).toBe(200);
const message = JSON.parse(event.data);
expert(messasge).toBe(expectedMessage);
done();
} catch (err) {
done(err);
}
});
postResult = axios.post(
`${config.APP_URL}/event`,
broadcastMessage
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment