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

Throw a helpful error when people use isFastboot instead of isFastBoot #814

Merged
merged 1 commit into from
Mar 18, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/ember-cli-fastboot/addon/services/fastboot.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ const FastBootService = Service.extend({
headers: deprecatingAlias('request.headers', { id: 'fastboot.headers-to-request', until: '0.9.9' }),
isFastBoot: typeof FastBoot !== 'undefined',

isFastboot: computed(function() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or should we warn here instead and return this.isFastBoot?

Copy link
Member

Choose a reason for hiding this comment

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

I think an assertion is fine, though I'd prefer if we didn't make this a computed (it will only assert the first time it is accessed I think).

We should consider migrating to native classes here, and then using a native getter directly. Unfortunately, we'll have to do this conditionally based on Ember version. We need to drop Ember < 3.12 support, would you mind making an issue for discussing that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created #815 for this. Should I just leave the PR until using a native getter is possible or?

assert(
'The fastboot service does not have an `isFastboot` property. This is likely a typo. Please use `isFastBoot` instead.',
false
);
}),

init() {
this._super(...arguments);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ module('Unit | Service | fastboot in the browser', function(hooks) {
assert.equal(service.get('isFastBoot'), false, `it should be false`);
});

test('isFastboot', function(assert) {
let service = this.owner.lookup('service:fastboot');
assert.throws(() => service.isFastboot, `it should throw`);
assert.throws(() => service.get('isFastboot'), `it should throw`);
});

test('request', function(assert) {
let service = this.owner.lookup('service:fastboot');
assert.equal(service.get('request'), null, `it should be null`);
Expand All @@ -24,4 +30,4 @@ module('Unit | Service | fastboot in the browser', function(hooks) {
let service = this.owner.lookup('service:fastboot');
assert.equal(service.get('metadata'), null, `it should be null`);
});
});
});