EmberJS-Unit Test Helpers



Unit Test Helpers

Globals Vs Modules

Some days ago, there was difficulty to test the Ember application without reloading the app as global. You can create the Ember application by using modules which require to be tested without removing the pieces out of the global application.

Unit Testing Helpers

When you create an application using Ember, it needs to be tested. Unit testing is basically used to test the code and ensure that it is doing what was intended. The default unit testing helper in Ember is Ember-QUnit where other test framework helpers can use it as a template.

Available Helpers

The Ember-QUnit has some of the test helpers as shown below −

  • moduleFor(fullName [, description, [,callbacks]])

    • fullName : It is name of the unit.

    • description : It is the description of the module.

    • callbacks : It represents the QUnit callbacks that needs other unit tests.

  • moduleForComponent(name [, description [, callbacks]])

    • name : It is name of the component.

    • description : It is the description of the module.

    • callbacks : It represents the QUnit callbacks that needs other unit tests.

  • moduleForModel(name [, description [, callbacks]])

    • name : It is name of the model.

    • description : It is the description of the module.

    • callbacks : It represents the QUnit callbacks that needs other unit tests.

  • test : It creates the test subject by using the 'subject' function.

  • setResolver : It sets the resolver in the application container to look up the objects.

Unit Testing Setup

To test your Ember application, you need to call Ember.setupForTesting(). The function setupForTesting() is going to off the loop execution of the Ember application. It controls the flow of loop execution and it resolves the async behaviour which are suspended to set up state and make assertions in known state. You can run the 'visit' to get particular URL and if you didn't use this, your assertion results would be unpredictable.

The Resolver

When testing your application, the Ember resolver provides the lookup functionality based on name, such as route:index or model:post. If you dont have custom resolver, then you need to set resolver as −

setResolver(Ember.DefaultResolver.create({ namespace: App }))
Advertisements