Skip to content

Commit

Permalink
consistently use the new view registry
Browse files Browse the repository at this point in the history
  • Loading branch information
ef4 committed Jul 28, 2015
1 parent 3315c6d commit 78ba0c0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
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

0 comments on commit 78ba0c0

Please sign in to comment.