L
L
Leonardo-lavanda2021-07-05 08:29:01
Software testing
Leonardo-lavanda, 2021-07-05 08:29:01

Why doesn't the input event object in Jest match the object in the browser?

Product testing on vue happens through jest and vue test utils. I set the value in the field via setValue:

it('should input only numbers', () => {
  const wrapper = shallowMount(CodeInput);
  wrapper.find('.code-input__cell').setValue('a');

  expect(wrapper.vm.value).toBeFalsy();
});


In the component code, I check through the data property that it is not a number entered:
onInput(e) {
  if (!Number.isInteger(Number(e.data))) return false;
// ...
}


I noticed that when running the tests, the execution ends at this check and realized that the data property does not exist in the test runtime:
onInput(e) {
    if (e.data) {
      console.log('data существует');
    } else {
      console.log('data не существует', { ...e })
    } 
// ...

}

60e298791e2a6153237834.png

Why is this done and how can I solve my problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question