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

fix: app.keys getter must have a setter either #3891

Merged
merged 2 commits into from Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/application.js
Expand Up @@ -271,6 +271,10 @@ class Application extends EggApplication {
return this[KEYS];
}

set keys(_) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get/set 最好还是成对出现,特别是覆盖属性的时候,避免重构踩坑。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

koajs/koa@287e589

koa 也改进了一下

// ignore
}

/**
* reference to {@link Helper}
* @member {Helper} Application#Helper
Expand Down
16 changes: 16 additions & 0 deletions test/app/extend/application.test.js
Expand Up @@ -209,4 +209,20 @@ describe('test/app/extend/application.test.js', () => {
assert(ctx.body === 'middleware resolution');
});
});

describe('app.keys', () => {
let app;
before(() => {
app = utils.app('apps/demo');
return app.ready();
});
after(() => app.close());

it('should work for app.keys and app.keys=', async () => {
assert.deepEqual(app.keys, [ 'foo' ]);
// `app.keys=` will be ignored
app.keys = undefined;
assert.deepEqual(app.keys, [ 'foo' ]);
});
});
});