Need help in ember unit testing


I am using mocha to unit test my ember app. I have an ember controller which has a statement - needs: [‘application’], which is blocking my unit test.

I am getting the following error while unit testing: specifies needs, but does not have a container. Please ensure this controller was instantiated with a container.

I am not getting this error while using my ember app but only when unit testing.

Please suggest any help.


What if in your test, you specify the application controller in needs, like this:

moduleFor('controller:index', 'Unit | Controller | index', {
  // Specify the other units that are required for this test.
  needs: ['controller:application']

Replace index with your controller.


Where exactly should I include this statement? Also can you please give a short explanation of what this means?


This would be in the generated controller test file when you ran ember generate controller XXX. moduleFor is the generic resolver built on top of QUnit’s module function but specific to Ember to load things from the container into your test. If other objects need to be loaded into the test, specify them by their resolver friendly name in needs.


Thank You. Unfortunately I do not use qunit.