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

Component was still attached to body instead of element from attachTo #1622

Closed
JeromeDeLeon opened this issue Jul 28, 2020 · 2 comments
Closed

Comments

@JeromeDeLeon
Copy link

JeromeDeLeon commented Jul 28, 2020

Version

1.0.3

Reproduction link

https://codesandbox.io/s/interesting-water-y2j31

Steps to reproduce

Run the test

What is expected?

The two logs of innerHTML of the body should have a parent of div with an id of app.

What is actually happening?

It attached the component directly in the body.


I don't know why the wrapper div document was getting removed just before mounting the component.

I found that createElement works just fine but if do that outside mount, it will not work.

I checked the tests made on #1492 and it was passing because it didn't check whether it was really attached on the div wrapper. It was just checking if the root is null but I don't think it's the right behavior. Correct me if I'm wrong.

@lmiller1990
Copy link
Member

I think this is correct. It looks like appendTo will actually replace whatever you pass - kind of like new Vue({ el: '#app' }) will replace <div id="app" /> with your Vue app. appendTo should probably be named mountAt or something, but yeah. Does that make sense?

Eg I changed your test:

test("displays message", () => {
  const div = document.createElement("div");
  div.id = "root";
  const s = document.createElement('span')
  s.appendChild(div)
  document.body.appendChild(s);

  console.log(document.body.innerHTML);
  // mount() returns a wrapped Vue component we can interact with
  const wrapper = mount(MessageComponent, {
    propsData: {
      msg: "Hello world"
    },
    attachTo: "#root"
  });

  console.log(document.body.innerHTML);

  // Assert the rendered text of the component
  expect(wrapper.text()).toContain("Hello world");
});

Logs are:

<span><div id="root"></div></span> 
<span><p>Hello world</p></span> 

@JeromeDeLeon
Copy link
Author

JeromeDeLeon commented Jul 29, 2020

😮 😮 😮 it took a minute before it made sense. Yeah. Thanks for this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants