@1024pix/ember-测试-图书馆
Ember测试库是用于测试Ember组件的非常轻量级的解决方案. 它在Ember内置帮助器上提供轻便的功能,鼓励更好的测试做法. 其主要指导原则是:
- 你的测试越像 你的软件使用的方式, 他们可以给你更多的信心.
更多信息,请访问 测试图书馆指导原则。 。 。 .
安装
npm install -D @1024pix/ember-testing-library @testing-library/dom @ember/test-helpers
使用量
Ember测试库允许在 Ember app中访问 Dom测试库查询. 关于 dom 测试库查询的更多信息,请查询 测试库文件。 。 。 .
目前可以使用的API方法如下:
- 获取史克林
- 在内部
- 访问
- 提交
- 单击ByName
- 点击文字
- 填充标签
- 选择标签和选项
- 选择可选的无线电组
- 获得 ByTextWithHtml
- 获取 AllByTextWithHtml 数据
- 查询ByTextWithHtml
- 查询 AllByTextWithHtml
- 找到 ByText With Html 数据
- 找到 AllByTextWithHtml 数据
请注意,Ember测试库不包括: userEvent 软件包,因此您应该使用 Ember 内置测试帮助器在集成/接受测试中与组件和/或DOM节点交互.
接受测试实例 :
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();
});
整合测试实例 :
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`<LoginForm />`);
// when
const button = screen.getByRole('button', { name: 'Login' });
await click(button);
// then
assert.dom(button).isDisabled();
});