Created
June 25, 2020 19:28
-
-
Save saml/ab310b0a73f703dcb4ac3d98a121dc54 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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