-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Ember 2.18 - Not possible to test instance-initializers #16216
Comments
Please provide a reproduction, this should absolutely be possible so maybe there is an error in the specific test in question... |
1. Codeexport function initialize(appInstance) {
let loggerService = appInstance.lookup('service:logger');
return loggerService.get('enabled');
}
export default {
initialize
}; 2. Testimport Application from '@ember/application';
import { run } from '@ember/runloop';
import { initialize } from 'dummy/instance-initializers/my-init';
import { module, test } from 'qunit';
import destroyApp from '../../helpers/destroy-app';
import EmberObject from '@ember/object';
module('Unit | Instance Initializer | my init', {
beforeEach() {
run(() => {
this.application = Application.create();
this.appInstance = this.application.buildInstance();
});
},
afterEach() {
run(this.appInstance, 'destroy');
destroyApp(this.application);
}
});
test('it should return true', function(assert) {
this.appInstance.register('service:logger', EmberObject.extend({enabled: true}))
assert.ok(initialize(this.appInstance));
}); 3. ErrorWhat happenedThe Real issue |
Yes, you can. See https://github.com/Serabe/ember-issue-16216 You need to use a Service to register a service. Closing this. Thank you! |
@Serabe Could you try with the latest ember 2.18? on 2.16 it works perfectly. And also, I forgot to mention: this happening for me on an addon project. |
Needs reproduction: I get the error |
If you remove the |
@stopdropandrew that worked and makes sense, thanks! (version 3.2) |
Hey,
as from 2.18 it is not possible to test instance initializers using current blueprint.
There are 2 errors:
When we built app instance
application.buildInstance()
it automatically boots app and fires the tested instance-initializer. So because of that, we are not able to prepare the test eg by registering own containers before running the initializer.The text was updated successfully, but these errors were encountered: