D
D
Dmitry Shooters2019-08-02 19:19:06
JavaScript
Dmitry Shooters, 2019-08-02 19:19:06

Why can one of two or more identical tests of one VUE component fail?

I ask a respected audience for help in mastering VUE testing. Or rather, in the first acquaintance with the testing of the component.
The suite implements a simple factory for riveting application instances via mount(). If I understand correctly, in each it() we should receive independent objects (instances)?
Trying to check working out at home after working vuelidate . Which in the house is called through onclick in the component.
In tests, it works quite logically, as planned (trigger.click, assigning values, working out validation). But I can't update the DOM in the second (and all subsequent tests in the suite and beyond) after the trigger. The first test patiently waits await NextTick()and the validator throws classes on the input. And everything is beautiful and as it should.
Tell me please. Why can't I repeat the same operation in the second same test? CHADNT?
I use a bunch of VUE + JEST.

describe("Validate login form", () => {

  const errors = ['error--text'];

  const factory = (values = {}) => {
    return mount(Login, {
      types, r,  i18n,  store,
      data () {
        return {
          ...values
        }
      }
    })
  };
  
  it("11111111111", async () => {

    const wrapper = factory({ email: "" });

    wrapper.find(".v-btn--block").trigger("click");

    await wrapper.vm.$nextTick();
    
    // expect( wrapper.vm.$v.email.$error ).toBe(true); // валидатор отрабатывает отлично
    
    // DOM обновляется, длинна контента ~4500 знаков, классы ошибок error--text есть 
    expect ( wrapper.find("label[for='email']").classes() ).toEqual(expect.arrayContaining(errors)); // true

  });

  it("222222222222", async () => {

    const wrapper = factory({ email: "" });

    wrapper.find(".v-btn--block").trigger("click");

    await wrapper.vm.$nextTick();

    // expect( wrapper.vm.$v.email.$error ).toBe(true); // валидатор отрабатывает отлично

    // DOM НЕ обновляется, длинна контента  ~3000 знаков, классов ошибок error--text нет
    expect ( wrapper.find("label[for='email']").classes() ).toEqual(expect.arrayContaining(errors)); // false

  });

});

PS Fans of manuals, I am happy to invite you to off. Jest documentation . Let's evaluate the description of the likely problem together:
If you have a test that often crashes when run inside a test suite, but doesn't crash when run alone, then something from another test is interfering with the current one.
Thanks, Cap.

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