-
Notifications
You must be signed in to change notification settings - Fork 277
Description
Hi all
What we have ?
We have three element:
- A button
- A simple html element
- A component
Scenario
When we click on the button, the element and the component are removed.
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
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();
});
