Skip to content

Commit

Permalink
Merge pull request #14850 from intercom/gj/test-exception-with-unknow…
Browse files Browse the repository at this point in the history
…n-service

add test verifying that registering an unknown service raises an exception
  • Loading branch information
rwjblue authored Jan 18, 2017
2 parents 516e93c + ccbc56b commit ca76dba
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/container/lib/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,9 @@ function buildInjections(/* container, ...injections */) {
}
}

container.registry.validateInjections(injections);
runInDebug(() => {
container.registry.validateInjections(injections);
});

for (let i = 0; i < injections.length; i++) {
injection = injections[i];
Expand Down
4 changes: 1 addition & 3 deletions packages/container/lib/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,9 +708,7 @@ Registry.prototype = {
for (let i = 0; i < injections.length; i++) {
fullName = injections[i].fullName;

if (!this.has(fullName)) {
throw new Error(`Attempting to inject an unknown injection: '${fullName}'`);
}
assert(`Attempting to inject an unknown injection: '${fullName}'`, this.has(fullName));
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2483,6 +2483,18 @@ moduleFor('Components test: curly components', class extends RenderingTest {
this.assertText('Jackson');
}

['@test injecting an unknown service raises an exception'](assert) {
this.registerComponent('foo-bar', {
ComponentClass: Component.extend({
missingService: inject.service()
})
});

expectAssertion(() => {
this.render('{{foo-bar}}');
}, 'Attempting to inject an unknown injection: \'service:missingService\'');
}

['@test can access `actions` hash via `_actions` [DEPRECATED]']() {
let component;

Expand Down

0 comments on commit ca76dba

Please sign in to comment.