admin管理员组文章数量:1334887
In Ember-CLI 1.13.1, I have the following integration test in my ponent:
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-prepile';
moduleForComponent('category-tabs', 'Integration | Component | category tabs', {
integration: true
});
test('tapping button fires an external action', function(assert) {
this.on('onTabTouch', function(value) {
assert.equal(value, 'Expense');
});
this.render(hbs`
{{category-tabs onTabTouch=(action "onTabTouch")}}
`);
this.$('button:first').click();
});
Then in my ponent, I have this action:
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
handleTabTouch(tab) {
this.attrs.onTabTouch(tab);
}
}
});
My test keeps on saying this:
An action named 'onTabTouch' was not found in [object Object].
How do I test a closure action? I also tried:
this.set('onTabTouch', function(value) {
assert.equal(value, 'Expense');
});
And it didn't work.
In Ember-CLI 1.13.1, I have the following integration test in my ponent:
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-prepile';
moduleForComponent('category-tabs', 'Integration | Component | category tabs', {
integration: true
});
test('tapping button fires an external action', function(assert) {
this.on('onTabTouch', function(value) {
assert.equal(value, 'Expense');
});
this.render(hbs`
{{category-tabs onTabTouch=(action "onTabTouch")}}
`);
this.$('button:first').click();
});
Then in my ponent, I have this action:
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
handleTabTouch(tab) {
this.attrs.onTabTouch(tab);
}
}
});
My test keeps on saying this:
An action named 'onTabTouch' was not found in [object Object].
How do I test a closure action? I also tried:
this.set('onTabTouch', function(value) {
assert.equal(value, 'Expense');
});
And it didn't work.
Share Improve this question edited Jul 26, 2015 at 7:40 Moppo 19.3k5 gold badges67 silver badges65 bronze badges asked Jul 26, 2015 at 5:59 Mikko PaderesMikko Paderes 8409 silver badges18 bronze badges1 Answer
Reset to default 12I've managed to figure it out.
Instead of writing:
this.on('onTabTouch', function(value) {
assert.equal(value, 'Expense');
});
I wrote this:
this.set('actions', {
onTabTouch(value) {
assert.equal(value, 'Expense');
}
});
EDIT:
A better way of doing it now is like this:
this.set('onTabTouch', () => assert.ok(true));
this.render(hbs`
{{category-tabs onTabTouch=(action onTabTouch)}}
`);
Notice that (action onTabTouch)
doesn't have any double quotes.
本文标签: javascriptEmber Integration Test for Closure ActionsStack Overflow
版权声明:本文标题:javascript - Ember Integration Test for Closure Actions - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742323451a2453254.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论