Need help in ember unit testing


#1

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.


#2

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.


#3

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


#4

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.

http://ember-cli.com/user-guide/#moduleforfullname-description-callbacks-delegate


#5

Thank You. Unfortunately I do not use qunit.