What is @ember/test-helpers?
@ember/test-helpers is a package that provides a set of utilities to facilitate testing in Ember.js applications. It offers a variety of helpers to interact with the DOM, handle asynchronous operations, and manage application state during tests.
What are @ember/test-helpers's main functionalities?
Rendering Helpers
Rendering helpers allow you to render components or templates in the test environment. This is useful for testing the output and behavior of your UI components.
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
await render(hbs`<MyComponent />`);
DOM Interaction
DOM interaction helpers enable you to simulate user interactions such as clicking buttons or filling in input fields. This helps in testing how your application responds to user actions.
import { click, fillIn } from '@ember/test-helpers';
await click('.my-button');
await fillIn('.my-input', 'new value');
Asynchronous Helpers
Asynchronous helpers like `settled` ensure that all asynchronous operations have completed before proceeding with the test. This is crucial for testing asynchronous behavior in your application.
import { settled } from '@ember/test-helpers';
await settled();
Routing Helpers
Routing helpers allow you to navigate to different routes within your application during tests. This is useful for testing the behavior of your application in different states and routes.
import { visit } from '@ember/test-helpers';
await visit('/my-route');
Other packages similar to @ember/test-helpers
ember-qunit
ember-qunit provides QUnit-specific helpers for testing Ember.js applications. It integrates seamlessly with @ember/test-helpers and offers additional utilities for setting up and tearing down tests.
ember-mocha
ember-mocha offers Mocha-specific helpers for testing Ember.js applications. Similar to ember-qunit, it works well with @ember/test-helpers and provides a Mocha-based testing environment.
ember-cli-page-object
ember-cli-page-object is a library for creating page objects in Ember.js tests. It provides a higher-level API for interacting with your application's UI, making tests more readable and maintainable.
@ember/test-helpers
A test-framework-agnostic set of helpers for testing Ember.js applications
Installation
If you are writing a regular Ember app or addon there is not much for you to
do as ember-qunit (and
ember-mocha) already include this
package as a dependency. You only need to make sure that you are using a
recent enough version of either one of these packages.
If you are working on ember-qunit
or ember-mocha
themselves you can
install this package like any other regular Ember addon.
Usage
This package exports several helper functions that can be used to improve
the testing experience when developing Ember.js apps or addons.
These helper functions include DOM interaction helpers (click()
, fillIn()
,
...), routing and rendering helpers (visit()
, render()
, ...) and some
other things that make it easy to write good tests.
The full documentation can be found in the API reference.
Contributing
Installation
git clone <repository-url>
cd ember-test-helpers
yarn install
Running tests
yarn test
(Runs ember try:each
to test your addon against multiple Ember versions)ember test
ember test --server
Running the dummy application
For more information on using ember-cli, visit https://ember-cli.com/.
Attribution
Much of ember-test-helpers
was extracted from the original ember-qunit
,
which was written by Stefan Penner, Robert Jackson, and Ryan Florence.
Copyright and License
Copyright 2015 Switchfly and contributors.
Dual-licensed under the Apache License, Version 2.0 and
the MIT License.