I have some integration tests which usually look like this:
test('can load with available teams', function () {
visit('/workforce/admin/organizations/create').then(function () {
var controller = App.__container__.lookup('controller:organizations.create');
...
});
});
The underscores in App.__container indicates (for me at least), that this is a private property and should not be accessed externally.
Is there a better way/pattern to achieve this?
During testing this is the best way to do it, you can create a test helper so as to avoid having to fix it in multiple places in the event that it changes in the future.
// register custom helper
Ember.Test.registerHelper('getController',
function(app, controllerName) {
return app.__container__.lookup('controller:' + controllerName);
}
);
test('dblClick link increments count', function() {
expect(2);
visit('/').then(function(){
var c = getController('index');
ok(c.get('good'));
ok(!c.get('bad'));
});
});
http://jsbin.com/jesuyeri/14/edit
You can also take advantage of ES6 when using @Kingpin2k's answer:
Ember.Test.registerHelper('getController',
(app, controllerName) => app.__container__.lookup('controller:' + controllerName)
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With