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

Consistently use the new view registry #90

Merged
merged 1 commit into from
Jul 28, 2015
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
16 changes: 11 additions & 5 deletions lib/ember-test-helpers/test-module-for-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default TestModule.extend({
thingToRegisterWith.injection(this.subjectName, 'layout', layoutName);
}

context.dispatcher = Ember.EventDispatcher.create();
context.dispatcher = this.container.lookup('event_dispatcher:main') || Ember.EventDispatcher.create();
context.dispatcher.setup({}, '#ember-testing');

this.callbacks.render = function() {
Expand Down Expand Up @@ -96,10 +96,17 @@ export default TestModule.extend({

this.actionHooks = {};

context.dispatcher = Ember.EventDispatcher.create();
context.dispatcher = this.container.lookup('event_dispatcher:main') || Ember.EventDispatcher.create();
context.dispatcher.setup({}, '#ember-testing');
context.actions = module.actionHooks;

// This thing is registered as "view:" instead of "component:"
// because only views get the necessary _viewRegistry
// injection. Which is arguably an Ember bug, but doesn't impact
// normal app usage since apps always use a "view:" at the top
// level.
(this.registry || this.container).register('view:test-holder', Ember.Component.extend());

context.render = function(template) {
if (!template) {
throw new Error("in a component integration test you must pass a template to `render()`");
Expand All @@ -110,9 +117,8 @@ export default TestModule.extend({
if (typeof template === 'string') {
template = Ember.Handlebars.compile(template);
}
module.component = Ember.Component.create({
layout: template,
container: module.container
module.component = module.container.lookupFactory('view:test-holder').create({
layout: template
});

module.component.set('context' ,context);
Expand Down
3 changes: 2 additions & 1 deletion lib/ember-test-helpers/test-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export default Klass.extend({
this.context = undefined;
unsetContext();

if (context.dispatcher) {
if (context.dispatcher && !context.dispatcher.isDestroyed) {
Ember.run(function() {
context.dispatcher.destroy();
});
Expand Down Expand Up @@ -230,6 +230,7 @@ export default Klass.extend({
this.container = items.container;
this.registry = items.registry;


var thingToRegisterWith = this.registry || this.container;
var router = resolver.resolve('router:main');
router = router || Ember.Router.extend();
Expand Down