Ember component creation error in 2.10

1.3k Views Asked by At

When I do Ember.Component.Create() in an unit test for mixin i get this error. I was upgrading ember from 1.13 to 2.10, this test worked fine in 1.13 but in 2.10 I get this error. Looks like in 2.10 ember component init requires an app instance.

Died on test #1     at Module.callback (http://localhost:4200/assets/tests.js:250:19)
    at Module.exports (http://localhost:4200/assets/vendor.js:131:32)
    at requireModule (http://localhost:4200/assets/vendor.js:30:18)
    at TestLoader.require (http://localhost:4200/assets/test-support.js:7104:7)
    at TestLoader.loadModules (http://localhost:4200/assets/test-support.js:7096:14)
    at Function.TestLoader.load (http://localhost:4200/assets/test-support.js:7126:22)
    at http://localhost:4200/assets/test-support.js:7009:18: Cannot instantiate a component without a renderer. Please ensure that you are creating <(subclass of Ember.Component):ember210> with a proper container/registry.@ 9 ms
Source:     
Error: Cannot instantiate a component without a renderer. Please ensure that you are creating <(subclass of Ember.Component):ember210> with a proper container/registry.
    at Class.init (http://localhost:4200/assets/vendor.js:51954:15)
    at Class.superWrapper [as init] (http://localhost:4200/assets/vendor.js:50175:22)
    at Class.init (http://localhost:4200/assets/vendor.js:50443:19)
    at Class.superWrapper (http://localhost:4200/assets/vendor.js:50175:22)
    at Class.init (http://localhost:4200/assets/vendor.js:50493:19)
    at Class.superWrapper (http://localhost:4200/assets/vendor.js:50175:22)
    at Class.exports.default._emberMetal.Mixin.create._Mixin$create.init (http://localhost:4200/assets/vendor.js:51000:17)
    at Class.superWrapper (http://localhost:4200/assets/vendor.js:50175:22)
    at Class.init (http://localhost:4200/assets/vendor.js:17472:19)
    at Class.superWrapper [as init] (http://localhost:4200/assets/vendor.js:50175:22)

Few things I have tried:

  • To startApp() in setup and destroy, similar to integration testi ng

  • To override init but init always requires _super() to be called

  • Tried to execute in integration testing environment where application is created

2

There are 2 best solutions below

0
On BEST ANSWER

I tried to do renderer: this.render or other options but nothing worked, finally based on the lead I got here

I did renderer: {} and it worked just fine.

There are other good solutions in the link too but its not needed in my scenario since I am not rendering anything.

2
On

I do not know if unit testing a component required Ember.Component.Create() at 1.13; but you should not create the component yourself during unit testing of components now; at least this is what I learned during dealing with Ember.

You should use moduleForComponent from ember-qunit with unit: true parameter and get the component simply with this.subject(); inside the test method.

I have created a twiddle for you to illustrate unit testing of a component with a mixin. I hope this helps.