Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emit more events #1395

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add custom event just in case
  • Loading branch information
tinovyatkin committed Oct 17, 2019
commit c719bdbd1d9ad50c6f8830510b757e6944d70a50
9 changes: 7 additions & 2 deletions test/application/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ describe('app emits events', () => {
it('should emit request, respond and responded once and in correct order', async() => {
const app = new Koa();
const emitted = [];
['request', 'respond', 'responded', 'error'].forEach(event => app.on(event, () => emitted.push(event)));
['request', 'respond', 'responded', 'error', 'customEvent'].forEach(event => app.on(event, () => emitted.push(event)));

app.use((ctx, next) => {
emitted.push('fistMiddleWare');
ctx.body = 'hello!';
return next();
});

app.use((ctx, next) => {
ctx.app.emit('customEvent');
return next();
});

app.use(ctx => {
emitted.push('lastMiddleware');
});
Expand All @@ -27,6 +32,6 @@ describe('app emits events', () => {
.get('/')
.expect(200);

assert.deepStrictEqual(emitted, ['request', 'fistMiddleWare', 'lastMiddleware', 'respond', 'responded']);
assert.deepStrictEqual(emitted, ['request', 'fistMiddleWare', 'customEvent', 'lastMiddleware', 'respond', 'responded']);
});
});