Skip to content

Commit

Permalink
test: add additional tests for emitSerial method
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jul 3, 2023
1 parent 1e6ab2b commit 5362084
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/emitter/emit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,34 @@ test.group('Emitter | emit | with error handler', (group) => {
emitter.on('new:user', [NewUser, 'sendEmail'])
await emitter.emit('new:user', { id: 1 })
}).waitForDone()

test('capture error using onError handler during emitSerial', async ({ assert }, done) => {
const app = new Application(BASE_URL, { environment: 'web', importer: () => {} })
const emitter = new Emitter(app)

emitter.onError((event, error) => {
assert.equal(event, 'new:user')
assert.equal(error.message, 'boom')
done()
})

emitter.on('new:user', () => {
throw new Error('boom')
})

await emitter.emitSerial('new:user', { id: 1 })
}).waitForDone()

test('throw error when no error listener is defined during emitSerial', async () => {
const app = new Application(BASE_URL, { environment: 'web', importer: () => {} })
const emitter = new Emitter(app)

emitter.on('new:user', () => {
throw new Error('boom')
})

await emitter.emitSerial('new:user', { id: 1 })
}).throws('boom')
})

test.group('Emitter | fake', () => {
Expand All @@ -291,6 +319,23 @@ test.group('Emitter | fake', () => {
assert.deepEqual(events.all(), [{ event: 'new:user', data: { id: 1 } }])
})

test('fake event with emitSerial', async ({ assert }) => {
const stack: any[] = []

const app = new Application(BASE_URL, { environment: 'web', importer: () => {} })
const emitter = new Emitter(app)

emitter.on('new:user', (data) => {
stack.push(data)
})

const events = emitter.fake(['new:user'])

await emitter.emitSerial('new:user', { id: 1 })
assert.deepEqual(stack, [])
assert.deepEqual(events.all(), [{ event: 'new:user', data: { id: 1 } }])
})

test('faking multiple times should drop old fakes', async ({ assert }) => {
const stack: any[] = []

Expand Down

0 comments on commit 5362084

Please sign in to comment.