2017-11-13 2 views
0

웹 응용 프로그램에서 ember-pikaday를 사용하고 있습니다. 내 데이트 구성 요소를 테스트하는 동안 문제가 발생했습니다. 값을 null로 설정하면 조치가 작성되지 않고 Y 인딩 값이 마지막으로 설정된 값으로 남습니다. 이것은 내 구성 요소입니다.값을 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을 준비했습니다.

답변

0

나는 대답을 ember-pikaday's test codes에서 발견했다.

대답은 다음과 같이 null로 값을 설정 한 후 맥락에서 아무 곳이나 클릭하는 것입니다

updateDateValue(this, null); 
this.$().click();