ember-pikaday 在值更改为 null 时不创建操作
ember-pikaday does not create action when value is changed to null
我在我的网络应用程序上使用 ember-pikaday。我在测试日期组件时遇到了问题。当该值设置为空时,不创建动作,绑定值保持最后设置的值。这是我的组件:
{{pikaday-input onSelection=(action 'onSelection') }}
这是我的测试。
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import moment from 'moment';
moduleForComponent('my-component', 'TODO: put something here', {
integration: true
});
function updateDateValue(_this, val){
let datecomponent = _this.$('input');
datecomponent.click();
datecomponent.val(val);
datecomponent[0].dispatchEvent(new Event('change'));
}
test('it renders', function(assert) {
let actionListenerValue;
this.on('myaction', function(val) { actionListenerValue=val; });
this.render(hbs`{{my-component onSelection=(action 'myaction') }}`);
updateDateValue(this, '01.04.2016');
assert.equal(this.$('input').val(), '01.04.2016');
assert.equal(moment(actionListenerValue).format('DD.MM.YYYY'), '01.04.2016');
updateDateValue(this, '05.02.2016');
assert.equal(this.$('input').val(), '05.02.2016');
assert.equal(moment(actionListenerValue).format('DD.MM.YYYY'), '05.02.2016');
updateDateValue(this, null);
assert.notOk(this.$('input').val());
assert.notOk(actionListenerValue); // this line throws error
});
我已经准备好了 twiddle 我的问题。
我在 ember-pikaday's test codes 上找到了答案。
答案是在将值设置为 null 后单击上下文中的任意位置,如下所示:
updateDateValue(this, null);
this.$().click();
我在我的网络应用程序上使用 ember-pikaday。我在测试日期组件时遇到了问题。当该值设置为空时,不创建动作,绑定值保持最后设置的值。这是我的组件:
{{pikaday-input onSelection=(action 'onSelection') }}
这是我的测试。
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import moment from 'moment';
moduleForComponent('my-component', 'TODO: put something here', {
integration: true
});
function updateDateValue(_this, val){
let datecomponent = _this.$('input');
datecomponent.click();
datecomponent.val(val);
datecomponent[0].dispatchEvent(new Event('change'));
}
test('it renders', function(assert) {
let actionListenerValue;
this.on('myaction', function(val) { actionListenerValue=val; });
this.render(hbs`{{my-component onSelection=(action 'myaction') }}`);
updateDateValue(this, '01.04.2016');
assert.equal(this.$('input').val(), '01.04.2016');
assert.equal(moment(actionListenerValue).format('DD.MM.YYYY'), '01.04.2016');
updateDateValue(this, '05.02.2016');
assert.equal(this.$('input').val(), '05.02.2016');
assert.equal(moment(actionListenerValue).format('DD.MM.YYYY'), '05.02.2016');
updateDateValue(this, null);
assert.notOk(this.$('input').val());
assert.notOk(actionListenerValue); // this line throws error
});
我已经准备好了 twiddle 我的问题。
我在 ember-pikaday's test codes 上找到了答案。
答案是在将值设置为 null 后单击上下文中的任意位置,如下所示:
updateDateValue(this, null);
this.$().click();