S
S
seredaes2020-07-22 17:51:48
Vue.js
seredaes, 2020-07-22 17:51:48

Why is the vue-test-utils test failing?

5f185192b226a812533854.png

There is a nice button that is disabled if the selectedOffers array is empty.

I am writing a test.

// проверка названия кнопки - совпало
    expect(wrapper.find("button[disabled='disabled']").text()).toEqual("Disallow selected");
    // проверка есть ли такая кнопка, так уже...ради интереса - есть
    expect(wrapper.find("button[disabled='disabled']").exists()).toBe(true);

    // вношу данные
    wrapper.setData({ "selectedOffers": [1, 2, 3] });
    // проверяю, действительно ли 3 элемента вмассиве
    expect(wrapper.vm.selectedOffers.length).toEqual(3);

<b>    // Вот в этом месте, не должно быть кнопки отключенной, но она есть !!!
    expect(wrapper.find("button[disabled='disabled']").exists()).toBe(false);</b>


5f18524663612507987604.png

I don't understand something, and there is no reactivity in the test? Those. the variable has changed, but nothing reacts, or should it be tested in some other way? Thanks in advance to all who answer.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Anton, 2020-07-22
@seredaes

this is probably the case:
https://ru.vuejs.org/v2/guide/reactivity.html#%D0%...
and something like this should work

wrapper.vm.nextTick().then(function(){
  expect(wrapper.find("button[disabled='disabled']").exists()).toBe(false)
})

or instead use
wrapper.setData({ "selectedOffers": [1, 2, 3] });
wrapper.vm.selectedOffers = [1, 2, 3];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question