From 78ba0c05538259ca7b7da14b4df385d21acb7971 Mon Sep 17 00:00:00 2001 From: Edward Faulkner Date: Tue, 28 Jul 2015 03:21:22 -0400 Subject: [PATCH] consistently use the new view registry --- .../test-module-for-component.js | 16 +++++++++++----- lib/ember-test-helpers/test-module.js | 3 ++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/ember-test-helpers/test-module-for-component.js b/lib/ember-test-helpers/test-module-for-component.js index 1136948aa..3e5553a50 100644 --- a/lib/ember-test-helpers/test-module-for-component.js +++ b/lib/ember-test-helpers/test-module-for-component.js @@ -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() { @@ -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()`"); @@ -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); diff --git a/lib/ember-test-helpers/test-module.js b/lib/ember-test-helpers/test-module.js index 442c84852..99aa59cba 100644 --- a/lib/ember-test-helpers/test-module.js +++ b/lib/ember-test-helpers/test-module.js @@ -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(); }); @@ -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();