Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attachToDocument deprecated and no documented substitute? #1584

Closed
ghost opened this issue Jun 17, 2020 · 4 comments · Fixed by #1611
Closed

attachToDocument deprecated and no documented substitute? #1584

ghost opened this issue Jun 17, 2020 · 4 comments · Fixed by #1611
Labels

Comments

@ghost
Copy link

ghost commented Jun 17, 2020

Subject of the issue

attachToDocument was deprecated, in favor of attachTo, which is supposed to be more flexible, by allowing any css selector as the mount point.

But what is the actual replacement for attachToDocument: true? attachTo: document.documentElement yields HierarchyRequestError: The operation would yield an incorrect node tree.

Seems like the functionality of attachToDocument was deprecated in favor of something that does not substitute it, but only provides complementary behaviour.

Note that, besides the hierarchy problem, attachTo should be acompanied by wrapper.destroy() at the end. The thing is that this DESTROYS THE NODE to which the wrapper was attached. So, I can attach the element to the body, but the body is going to be destroyed in the call.

What I'm currently doing is adding a dumb routine to each test suite that needs the wrapper to be attached to the dom:


    var node = document.createElement("div");
    node.setAttribute('id', 'app')
    document.body.appendChild(node);

    const wrapper = mount(List, {
      attachTo: '#app'
    }

    ...

    wrapper.destroy() 

Needless to say, unless I'm missing something, it would be way easier to not have attachToDocument deprecated.

@afontcu
Copy link
Member

afontcu commented Jun 18, 2020

Hi! Thanks for filling this in.

attachTo does provide a substitute for attachToDocument. #1580 might help.

and AFAIK, attachToDocument also required you to call wrapper.destroy() at the end of the test to make sure a test wouldn't pollute the next one.

@ghost
Copy link
Author

ghost commented Jun 22, 2020

The alternative solution requires a lot of boilerplate code though. Creating a div, appending it to the body, then calling attachTo. Makes one miss the good old times of attachToDocument.

@ghost
Copy link
Author

ghost commented Jun 30, 2020

Also, the solution there leaves a warning, and one should still add:


    const app = document.createElement('div');
    app.setAttribute('data-app', true);
    document.body.append(app);

So the full boilerplate code for every test that uses, say, a dialog, is something like this:


    const elem = document.createElement('div')
    document.body.appendChild(elem)

    const app = document.createElement('div');
    app.setAttribute('data-app', true);
    document.body.append(app);


So the convenience of the old attachToDocument is still huge.

@afontcu
Copy link
Member

afontcu commented Jul 8, 2020

Also, the solution there leaves a warning, and one should still add

I believe (haven't actually check!) that this is due to Vuetify, which requires a data-app attribute (or wrapping your component under testing with <v-app>).

lmiller1990 pushed a commit that referenced this issue Jun 13, 2021
Closes #1725

Updates  attachToDocument documentation tip from the div boilerplate from #1584 & #1611 to the new handling from #1578 & #1699
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant