Skip to content

Commit

Permalink
Tweak test
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeepers committed Dec 8, 2017
1 parent 015ad53 commit 5d180fb
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions tests/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,21 @@ describe('server', () => {
})

describe('events', () => {
it('emits events', async () => {
const spy = jest.fn()
it('emits events', async (done) => {
const payload = {payload: true}

events.addEventListener('message', (message) => {
spy(message)
})
await request(server).post(channel)
.set('X-Foo', 'bar')
.send(payload)
.expect(200)

const res = await request(server).post(channel).send({ payload: true })
expect(res.status).toBe(200)
expect(spy).toHaveBeenCalled()
events.addEventListener('message', (msg) => {
const data = JSON.parse(msg.data)
expect(data.body).toEqual(payload)
expect(data['x-foo']).toEqual('bar')
// test is done if all of this gets called
done()
})
})
})

Expand Down

0 comments on commit 5d180fb

Please sign in to comment.