How to register the component for testing with ember-qunit?

Hi.

I’m trying to use ember-qunit for testing. I have this code here: (http://jsbin.com/zejacati/5/edit)

Ember.Foo = Ember.Namespace.create();

Ember.Foo.FooComponent = Ember.Component.extend({
  template: Ember.Handlebars.compile('<h2>Hello!</h2>')
});

Ember.Handlebars.helper('foo-component', Ember.Foo.FooComponent);

window.App = Ember.Application.create();

window.App.setupForTesting();
emq.globalize();
setResolver(Ember.DefaultResolver.create({
  namespace: window.App
}));

moduleForComponent('foo-component', 'Foo component testing');

test('First true test', function () {
  var component = this.subject();
  ok(true, true);
});

and ember sayed me:

Setup failed on First true test: Attempting to register an unknown factory: component:foo-component

I think the problem in resolver, but I don’t know how fix it.

Any ideas?

Thank you.

First of all, I would recommend you to take a look on the official testing guide - components section.

Your bin has some errors:

  • you are using a QUnit 1.14.1-pre version that differs form the one used in the official examples (QUnit 1.14.0)
  • some HTML elements in section
  • missing < div id="ember-testing " > < / div > in body
  • using a deprecated method assigning template in the component
  • you’ve created a name space and it wasn’t assigned to the ember core Object (Ember.Foo = Ember.Namespace.create():wink: ← this is really messy and you’ve shouldn’t do this
  • components should be named like FooBarComponent so you can reference it via {{foo-bar}}
  • some other issues

you can check a working modified version of your bin http://jsbin.com/zejacati/13/edit

1 Like