Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
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.
The npm package ember-testing-library receives a total of 2 weekly downloads. As such, ember-testing-library popularity was classified as not popular.
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.