Ember.js 如何从测试组件触发余烬组件中的函数?
在单元测试ComponentA测试中,我希望触发ComponentA中的函数加载,但在这样做时遇到问题Ember.js 如何从测试组件触发余烬组件中的函数?,ember.js,ember-qunit,Ember.js,Ember Qunit,在单元测试ComponentA测试中,我希望触发ComponentA中的函数加载,但在这样做时遇到问题 test('should render some information', async function (assert)) { await render(hbs`{{componentA}}`); assert.euqal(".info").text().trim(), "info text"); } 在下面的代码示例中的assert.equ
test('should render some information', async function (assert)) {
await render(hbs`{{componentA}}`);
assert.euqal(".info").text().trim(), "info text");
}
在下面的代码示例中的assert.equal之前,我想向this.load添加一些simular,我应该在组件中编写它来触发它。但我似乎找不到这样做的正确语法
test('should render some information', async function (assert)) {
await render(hbs`{{componentA}}`);
assert.euqal(".info").text().trim(), "info text");
}
这里可以做一些事情,但这取决于加载是否是一个动作。可能还有其他方法来测试这一点,但这些是我使用的最常用的方法 如果加载是一个动作,由DOM事件触发,即单击按钮,则可以通过在集成测试中执行该DOM事件来触发该函数:
test('should render some information', async function(assert) {
await render(hbs`{{componentA}}`);
// if a button has the action modifier:
// <button {{action "load"}}>Click me</button>
// then you can do this in your test to trigger the action:
await click('button');
// assertions go here
});
这是一个常规函数,因此我将尝试第二个建议。非常感谢你@不客气。只需确保将其放在单元测试文件中,该文件与组件的集成测试文件不同!它应该放在tests/unit/components/-test.js中