Upgrading from an earlier version? Have a look at our Upgrade Guide below.
Ember Mocha can also be installed with bower and used directly in any Ember project:
$ bower install ember-mocha
You can then choose to include the global (
ember-mocha.js) or AMD
ember-mocha.amd.js) build when running your tests.
You'll typically want to set a single resolver for your test suite:
If you want to use multiple resolvers in your test suite, you can also
setResolver in the
beforeSetup callback of your test modules.
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.
For example, the following is a unit test for the
The subject is specified as
controller:sidebar, which is the key that will
be used to look up this controller in the isolated container that will be
created for this test.
setupComponentTest function is specifically designed to test components
and provides additional
$ helpers within a test's context.
setupModelTest function can be used to test Ember Data models and
provides an additional
store helper within a test's context.
setupAcceptanceTest function can be used to run acceptance
tests as the name suggests. It will automatically setup an
application instance for you, which is provided at
;;;var Application = EmberApplication;;
In case your project supports the
async/await feature of ES2016 you can
simplify the test function to this:
asynckeyword in front of the test
awaitin front of all async test helper calls
Previous releases promoted the use of
describeModel() instead of the
function of Mocha itself. These functions have been deprecated and replaced
setupTest() functions mentioned above. The following
example will explain how to update your code.
describeModuleimport with a
setupTest()call to the test
functionwith the second and third argument of the
describeModule()call (module name and options)
describeModule()call with a
describe()call with the first and fourth argument of the
describeModule()call (description and test function)
Instead of refactoring all your files by hand we recommend to use the ember-mocha-codemods to automatically convert your tests:
npm install -g jscodeshift jscodeshift -t https://raw.githubusercontent.com/Turbo87/ember-mocha-codemods/master/import-it-from-mocha.js tests jscodeshift -t https://raw.githubusercontent.com/Turbo87/ember-mocha-codemods/master/new-testing-api.js tests
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 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.
This repository also contains the
ember-mocha-adapter originally developed
by Teddy Zeenny at
https://github.com/teddyzeenny/ember-mocha-adapter/ under the MIT license.