lundi 13 novembre 2017

ember-pikaday does not create action when value is changed to null

I'm using ember-pikaday on my web application. I have faced a problem while I'm testing my date component. When the value is set to null, it does not create action, and the binding value remains the last setted value. This is my component:



This is my test.

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``);

  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

});

I have prepared a twiddle of my problem.




Aucun commentaire:

Enregistrer un commentaire