Upgrading from an earlier version? Have a look at our Migration Guide.
- Ember.js v3.4 or above
- Ember CLI v2.13 or above
- Node.js 8 or above
ember-mocha is an Ember CLI addon, so install it
as you would any other addon:
$ ember install ember-mocha
Some other addons are detecting the test framework based on the installed
addon names and are expecting
ember-cli-mocha instead. If you have issues
with this then
ember install ember-cli-mocha, which should work exactly
For the older APIs have a look at our Legacy Guide.
Setting the Application
tests/test-helper.js file should look similar to the following, to
correctly setup the application required by
Also make sure that you have set
ENV.APP.autoboot = false; for the
environment in your
setupTest() function can be used to setup a unit test for any kind
of "module/unit" of your application that can be looked up in a container.
It will setup your test context with:
this.ownerto interact with Ember's Dependency Injection system
this.pauseTest()method to allow easy pausing/resuming of tests
For example, the following is a unit test for the
If you find that test helpers from other addons want you to pass a
object you can do so like this:
let hooks = ;;
This will make sure that in functions passed to
this.owner and other things that
setupTest() sets up are still available.
Mocha itself runs
afterEach hooks in a different order than QUnit, which is
why this "workaround" is sometimes needed.
Setup Rendering Tests
setupRenderingTest() function is specifically designed for tests that
render arbitrary templates, including components and helpers.
It will setup your test context the same way as
setupTest(), and additionally:
- Initializes Ember's renderer to be used with the
this.elementto your test context which returns the DOM element representing the wrapper around the elements that were rendered via
- sets up the DOM Interaction Helpers
Setup Application Tests
setupApplicationTest() function can be used to run tests that interact
with the whole application, so in most cases acceptance tests.
On top of
setupTest() it will:
- Boot your application instance
- Set up all the DOM Interaction Helpers
fillIn(), ...) as well as the Routing Helpers (
currentURL(), ...) from
For instructions how to upgrade your test suite please read our Migration Guide.
Contributions are welcome. Please follow the instructions below to install and test this library.
In order to test in the browser:
... and then visit http://localhost:4200/tests.
In order to perform a CI test:
Copyright and License
Copyright 2014 Switchfly
This product includes software developed at Switchfly (http://www.switchfly.com).
NOTICE: Only our own original work is licensed under the terms of the Apache License Version 2.0. The licenses of some libraries might impose different redistribution or general licensing terms than those stated in the Apache License. Users and redistributors are hereby requested to verify these conditions and agree upon them.