![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
ember-mocha2
Advanced tools
ember-mocha2 simplifies testing of Ember applications with Mocha by providing Mocha-specific wrappers around the helpers contained in @ember/test-helpers.
Upgrading from an earlier version? Have a look at our Migration Guide.
ember-mocha2
is an Ember CLI addon, so install it
as you would any other addon:
$ ember install ember-mocha2
The following section describes the use of Ember Mocha with the latest modern Ember testing APIs, as laid out in the RFCs 232 and 268.
For the older APIs have a look at our Legacy Guide.
Your tests/test-helper.js
file should look similar to the following, to
correctly setup the application required by @ember/test-helpers
:
import Application from '../app';
import config from '../config/environment';
import { setApplication } from '@ember/test-helpers';
import { start } from 'ember-mocha2';
import chai from 'chai';
import chaiDom from 'chai-dom';
chai.use(chaiDom)
setApplication(Application.create(config.APP));
start();
Also make sure that you have set ENV.APP.autoboot = false;
for the test
environment in your config/environment.js
.
The 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.owner
to interact with Ember's Dependency Injection
systemthis.set()
, this.setProperties()
, this.get()
, and this.getProperties()
this.pauseTest()
method to allow easy pausing/resuming of testsFor example, the following is a unit test for the SidebarController
:
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupTest } from 'ember-mocha2';
describe('SidebarController', function() {
setupTest();
// Replace this with your real tests.
it('exists', function() {
let controller = this.owner.lookup('controller:sidebar');
expect(controller).to.be.ok;
});
});
If you find that test helpers from other addons want you to pass a hooks
object you can do so like this:
let hooks = setupTest();
setupMirage(hooks);
This will make sure that in functions passed to hooks.afterEach()
the
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.
Sometimess you will need to specify that tests should not wait for settled state.
If you see timeout errors in an afterEach
hook for your tests update your setupTest
cal:
describe('SidebarController', function() {
setupTest({ waitForSettled: false });
The 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:
render()
this.element
to your test context which returns the DOM element
representing the wrapper around the elements that were rendered via
render()
@ember/test-helpers
(click()
, fillIn()
, ...)import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupRenderingTest } from 'ember-mocha2';
import { render } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
describe('GravatarImageComponent', function() {
setupRenderingTest();
it('renders', async function() {
await render(hbs`{{gravatar-image}}`);
expect(this.element.querySelector('img')).to.exist;
});
});
The 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:
click()
, fillIn()
, ...) as well as the Routing Helpers
(visit()
, currentURL()
, ...) from @ember/test-helpers
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupApplicationTest } from 'ember-mocha2';
import { visit, currentURL } from '@ember/test-helpers';
describe('basic acceptance test', function() {
setupApplicationTest();
it('can visit /', async function() {
await visit('/');
expect(currentURL()).to.equal('/');
});
});
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.
yarn
In order to test in the browser:
yarn test --server
In order to perform a CI test:
yarn 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.
FAQs
Mocha helpers for testing Ember.js applications
The npm package ember-mocha2 receives a total of 0 weekly downloads. As such, ember-mocha2 popularity was classified as not popular.
We found that ember-mocha2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.