我偶然发现了这个问题,同时也在寻找一种方法来测试集成测试中的冒泡操作(而不是关闭操作)。也许您已经找到了解决方案,但我会回答让下一个人比我更早找到它。
测试一个动作是否被调用的惯用方法是编写一个模拟函数并断言它将被调用。在您的示例中 - 在关闭操作之前 - 编写这种测试的方法如下:
test('it closes the create dialog when close btn is clicked', function(assert) {
// make sure our assertion is actually tested
assert.expect(1);
// bind the action in the current test
this.on('cancelAction', (actual) => {
let expected = { whatever: 'you have expected' };
assert.deepEquals(actual, expected);
// or maybe just an assert.ok(true) - but I am not sure if this is "good" style
});
this.render(hbs`{{group-create cancelCreateAction="cancelAction"}}`)
this.$('button.btn--primary').click()
expect('myAction').to.be.called?
});
如今,使用闭包动作范例,绑定模拟函数的正确方法是
// bind the action in the current test
this.set('cancelAction', (actual) => {
let expected = { whatever: 'you have expected' };
assert.deepEquals(actual, expected);
});
this.render(hbs`{{group-create cancelCreateAction=(action cancelAction)}}`)