Skip to content

The VueWrapper does not update by itself #1106

@KalDev468

Description

@KalDev468

Hi all

What we have ?

We have three element:

  1. A button
  2. A simple html element
  3. A component

Scenario

When we click on the button, the element and the component are removed.

carbon (3)

Tests

The first test:

  • Check that the element exist in the beginning
  • Click on the button
  • Check that the element no longuer exist

The second test: (Same as the first but for the component)

  • Check that the component exist in the beginning
  • Click on the button
  • Check that the component no longuer exist

carbon (5)

Result

The first test works in both versions of VTU.
The second test only works in VTU but fail in VTU-next.

Problem

For the DomWrapper it is necessary to re-search the element to have its new state. this behavior is the same in both versions of VTU, so nothing changed.
But for the VueWrapper, in VTU, it was not necessary to re-search the component to have its new state, the wrapper updated itself. which is no longer the case in VTU-next. so this is the identified change

Debug

Difference between the two versions (after the action of the click, therefore after removing the element|component):

For DomWrappe: there is no difference, it is always necessary to redo a search to have the new state of the wrapper.

For VueWrapper: without redoing the search

VTU version/Method exist() html()
VTU(Vue 2) false HTML code
VTU-next(Vue 3) true TypeError: Cannot read property 'vue_app' of null

Questions

Is that the new behavior or is it a bug?
If this is the new VueWrapper behavior, do we need to re-search the component after every action or is there a better solution?

Code

import {mount} from "@vue/test-utils";

const componentA: any = {
    template: `<div>component</div>`
}

const app = {
    template: `
        <div>
            <button @click="isOpen = false">close</button>
            
            <!-- REMOVE AFTER CLICK ON THE BUTTON -->
            <div id="element" v-if="isOpen">element</div>
            <componentA v-if="isOpen"/>
        
        </div>
    `,
    components: {componentA},
    data() {
        return {isOpen: true}
    }
}

test('Element must not exist', async () => {
    let wrapper = mount(app);
    let buttonWrapper = wrapper.find('button');
    let elementWrapper = wrapper.find('#element');

    expect(elementWrapper.exists()).toBeTruthy();

    await buttonWrapper.trigger('click');

    elementWrapper = wrapper.find('#element'); // NECESSARY in both versions of VTU

    expect(elementWrapper.exists()).toBeFalsy();
});

test('Component must not exist', async () => {
    let wrapper = mount(app);
    let buttonWrapper = wrapper.find('button');
    let componentWrapper = wrapper.findComponent(componentA);

    expect(componentWrapper.exists()).toBeTruthy();

    await buttonWrapper.trigger('click');

    // componentWrapper = wrapper.findComponent(componentA);// NECESSARY ONLY IN VUT-NEST

    expect(componentWrapper.exists()).toBeFalsy();
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions