我偶然發現了這個問題,同時尋找一種方式來測試泡了在集成測試(而不是封閉行爲 )行動。也許你已經找到了解決方案,但我會回答讓下一個人比我更早找到它。
測試動作是否被調用的慣用方式是編寫一個模擬函數並聲明它將被調用。 在您的例子 - 之前關閉行動 - 寫這種測試的方法如下:
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)}}`)
不能在燼2.1.0中做這樣的事情。你如何導入'click'和'andThen'功能? – user1952811
從'qunit'導入{module,test}; 從'../helpers/start-app'導入startApp; –
你仍然會爲'andThen'和'click'定義一個undefined。你從哪裏進口? – user1952811