https://github.com/1024pix/ember-testing-library
Simple and complete Ember DOM testing utilities that encourage good testing practices.
https://github.com/1024pix/ember-testing-library
Last synced: 6 months ago
JSON representation
Simple and complete Ember DOM testing utilities that encourage good testing practices.
- Host: GitHub
- URL: https://github.com/1024pix/ember-testing-library
- Owner: 1024pix
- License: mit
- Created: 2021-10-13T14:52:40.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-01-08T01:28:36.000Z (9 months ago)
- Last Synced: 2025-04-01T23:04:44.816Z (6 months ago)
- Language: JavaScript
- Homepage:
- Size: 3.83 MB
- Stars: 1
- Watchers: 12
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# @1024pix/ember-testing-library
The Ember Testing Library is a very lightweight solution for testing Ember components. It provides light utility functions on top of Ember built-in helpers, in a way that encourages better testing practices. Its primary guiding principle is:
- The more your tests resemble the way your software is used, the more confidence they can give you.
For more info, please visit [testing library guiding principles](https://testing-library.com/docs/guiding-principles).
## Compatibility
- Ember.js v4.12 or above
- Ember CLI v4.12 or above
- Node.js v18 or above## Installation
```
ember install @1024pix/ember-testing-library
```## Usage
Ember testing library gives access to dom testing library queries in an Ember app. For more info on dom testing library queries, follow [Testing library doc](https://testing-library.com/docs/dom-testing-library/api/).
The current API methods that can be used are as follows:
- getScreen
- within
- visit
- render
- clickByName
- clickByText
- fillByLabel
- selectByLabelAndOption
- selectOptionInRadioGroup
- getByTextWithHtml
- getAllByTextWithHtml
- queryByTextWithHtml
- queryAllByTextWithHtml
- findByTextWithHtml
- findAllByTextWithHtmlPlease note that Ember Testing Library does not include the userEvent package, and that you should therefore use Ember built-in test helpers to interact with components and/or DOM nodes in integration/acceptance tests.
### Acceptance test example:
```js
import { visit } from '@1024pix/ember-testing-library';
import { click } from '@ember/test-helpers';test('it should disable the button when clicked', async function (assert) {
// given
const screen = await visit('/home');// when
const button = screen.getByRole('button', { name: 'Send message' });
await click(button);// then
assert.dom(button).isDisabled();
});
```### Integration test example:
```js
import { render } from '@1024pix/ember-testing-library';
import { click } from '@ember/test-helpers';test('it should disable the button when clicked', async function (assert) {
// given
const screen = await render(hbs``);// when
const button = screen.getByRole('button', { name: 'Login' });
await click(button);// then
assert.dom(button).isDisabled();
});
```## Contributing
See the [Contributing](CONTRIBUTING.md) guide for details.
## License
This project is licensed under the [MIT License](LICENSE.md).