
Ember QUnit simplifies unit testing of Ember applications with QUnit by providing QUnit-specific wrappers around the helpers contained in ember-test-helpers.
;; ; ;Component integration tests are the default mode for moduleForComponent. You can still explicitly activate them by passing integration: true.
Integration tests have the advantage of testing your component as Ember would actually use them. It's helpful to think of this mode as simply testing the inputs and outputs of the component. These tests allow you interact with both the bound values that are passed into the component as well as its resulting actions.
Component integration tests have the following features:
this acts as the outer context for the component. As a result, you can call this.set and this.on to setup values and event listeners that you can then have interact with the component.this.render(hbs`{{ your-component-name value=value action="updated" }}`). You can render other components as well as block content.this.$().needs:. Doing so will force the test into unit mode.this.subject() will raise an exception).; ; // run a test;Unit tests used to be the default mode for component tests. To flag a test as a unit test, either specify unit: true or include needs: [] in the callbacks object.
Unit tests have the advantage of giving you direct access to the component instance so you can test its internals. Unit tests have the following features:
this.subject().this.render() or this.$().this.$().needs: [] option. This includes helpers, services, partials, and any other components (with their templates) that are referenced.didInsertElement and willDestroyElement will be called, but the remaining hooks introduced in Ember 1.13.x will not be.; ; ;moduleFor works for any object you could look up with the Ember Resolver (service, routes, controllers, etc.).
Note: Controllers / Routes do not have access to rendering. You will need to either use a component test or an acceptance test.
; ; ;// if you don't have a custom resolver, do it like this:; // otherwise something like:;;;Under the hood, if you use Ember.RSVP.Promise, ember-qunit will call
QUnit's start and stop helpers to stop the test from tearing down
and running other tests while your asynchronous code runs. ember-qunit
also asserts that the promise gets fulfilled.
In addition, you can also return promises in the test body:
// If you return a promise from a test callback it becomes an asyncTest. This// is a key difference between ember-qunit and standard QUnit.;If an error is thrown in your promise or a promise
within test becomes rejected, ember-qunit will fail the test.
To assert that a promise should be rejected, you can "catch"
the error and assert that you got there:
;moduleFor(fullName [, description [, callbacks]])fullName: (String) - The full name of the unit, ie
controller:application, route:index.
description: (String) optional - The description of the module
callbacks: (Object) optional
beforeEach and afterEach)subject)integration: true or unit: true (default: integration: true)needs specify any dependencies the tested module will require.moduleForComponent(name, [description, callbacks])name: (String) - the short name of the component that you'd use in a
template, ie x-foo, ic-tabs, etc.
description: (String) optional - The description of the module
callbacks: (Object) optional
beforeEach and afterEach)subject)integration: true or unit: true (default: integration: true)needs specify any dependencies the tested module will require. (Including this will force your test into unit mode).moduleForModel(name, [description, callbacks])name: (String) - the short name of the model you'd use in store
operations ie user, assignmentGroup, etc.
description: (String) optional - The description of the module
callbacks: (Object) optional
beforeEach and afterEach)subject)integration: true or unit: true (default: integration: true)needs specify any dependencies the tested module will require.git clone <repository-url> this repositorycd ember-qunitnpm installember servenpm test (Runs ember try:each to test your addon against multiple Ember versions)ember testember test --serverember buildFor more information on using ember-cli, visit https://ember-cli.com/.