Test Fixture class for Ember UI components, providing a UI interface for test cases.
- Ember.js v3.28 or above
- Ember CLI v3.28 or above
- Node.js v14 or above
ember install ember-test-fixture
See this guide slides for more details.
class FooFixture extends Fixture {
constructor() {
super('data-test-root');
}
@element emailField;
@element commitButton;
async enterEmail(email) {
await this.emailField.fillIn(email);
return this.commitButton.click();
}
}
Each fixture class represents a UI component and encapsulates all implementation details for interacting with the UI component.
By offloading the UI interaction details to these classes, tests can focus on the behaviors being tested rather than the implementation specifics.
Ember test fixtures employ Chai's BDD (Behavior-Driven Development) style testing syntax. Developers can use these fixture classes to set up action methods representing the UI component's behaviors, making the tests read more like plain English.
As mentioned above, each fixture class represents a UI component. Since UI components can be extended to create new components or composed of other components, test fixtures can also be extended or composed of other fixtures.
Test fixtures, by default, utilize BEM-inspired data-test- data attributes for selectors. If the UI component the fixture represents follows the BEM-style data-test- attributes for its root and child elements, the fixture will automatically infer the selectors for its elements based on their names in the test fixture.
<!-- Foo component template -->
<div data-test-foo>
<header data-test-foo__title></header>
<button data-test-foo__submit-button></button>
</div>
class FooFixture extends Fixture {
constructor() {
super('data-test-foo');
}
@element title;
@element submitButton;
}