Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
ember-testing-library
Advanced tools
Simple and complete Ember DOM testing utilities that encourage good testing practices.
Simple and complete Ember DOM testing utilities that encourage good testing practices.
Please note that this version of the library is not backed by DOM Testing Library like the versions for React, Vue, etc. are. I made this addon because there is no official Ember version yet.
This addon can be installed via Ember CLI as such:
ember install ember-testing-library
The recommended way to use this addon is through the setupScreen
function. This function automatically injects the DOM Testing Library screen into every test in a given module.
import { setupRenderingTest } from 'ember-qunit';
import { module, test } from 'qunit';
import { TestContext as BaseTestContext } from 'ember-test-helpers';
import { setupScreen, ScreenTestContext } from 'ember-testing-library';
interface TestContext extends BaseTestContext, ScreenTestContext {}
module('Integration | Component | Example', function (hooks) {
setupRenderingTest(hooks);
setupScreen(hooks);
test('it works as expected', async function (this: TestContext, assert) {
await render(hbs`<MyComponent />`);
assert.dom(this.screen.getByLabelText('My text field') as HTMLElement).exists();
});
});
Once this function has been called, this.screen
can be accessed in every test
in your module. The functions available in this.screen
are one to one with the queries available in the standard edition of DOM Testing Library. For a thorough list of these, you can see the official docs.
If you don't want to inject this.screen
into every test in your module, you can use the getScreen
to access the DOM Testing Library screen as a one off whenever you desire.
import { setupRenderingTest } from 'ember-qunit';
import { module, test } from 'qunit';
import { getScreen } from 'ember-testing-library';
module('Integration | Component | Example', function (hooks) {
setupRenderingTest(hooks);
test('it works as expected', async function (assert) {
await render(hbs`<MyComponent />`);
const screen = getScreen();
assert.dom(screen.getByLabelText('My text field') as HTMLElement).exists();
});
});
This addon does not expose an equivalent to fireEvent
like the other framework versions of DOM Testing Library do. Instead, it is recommended you use @ember/test-helpers
in conjunction with this addon for event triggering purposes.
import { render, click } from '@ember/test-helpers';
import { setupRenderingTest } from 'ember-qunit';
import { module, test } from 'qunit';
import { TestContext as BaseTestContext } from 'ember-test-helpers';
import hbs from 'htmlbars-inline-precompile';
import sinon, { SinonSpy } from 'sinon';
import { setupScreen, ScreenTestContext } from 'ember-testing-library';
interface TestContext extends BaseTestContext, ScreenTestContext {
spy: SinonSpy;
}
module('Integration | Component | Example', function (hooks) {
setupRenderingTest(hooks);
setupScreen(hooks);
hooks.beforeEach(function (this: TestContext) {
this.spy = sinon.spy();
});
test('it works as expected', async function (this: TestContext, assert) {
await render(hbs`<MyComponent @onClick={{this.spy}} />`);
await click(this.screen.getByText('My button') as HTMLElement);
assert.ok(this.spy.calledOnce);
});
});
FAQs
Simple and complete Ember DOM testing utilities that encourage good testing practices.
We found that ember-testing-library 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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.