Skip to content

Query selectors used within components do not seem to work correctly within tests #852

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

Closed
benm-eras opened this issue Jul 25, 2018 · 1 comment
Labels

Comments

@benm-eras
Copy link

benm-eras commented Jul 25, 2018

Version

1.0.0-beta.21

Reproduction link

https://github.com/benm-eras/VueDemo

Steps to reproduce

I have used the latest version of Vue CLI to scaffold and app, and added a simple component to demonstrate my issue. Clone the repo, then just run the tests with yarn run test. The mounted function on MyComponent.vue will write a couple of NodeLists to the console. The first is all the children of the root element, the second should be only those with the page class.

What is expected?

In both tests 3 div elements with the class page are added to the default slot. In the second test a single div with the class shade is added before the pages. In both tests it would be expected that .querySelectorAll(".page") would return the 3 .page divs, and they would be printed to the console.

What is actually happening?

In the second test .querySelectorAll(".page") is not returning anything at all. Printing all the child nodes to the console (the first console.info(...) in each test) shows the following:

NodeList {
  '0': HTMLDivElement { _prevClass: 'shade' },
  '1': HTMLDivElement { _prevClass: 'shade' },
  '2': HTMLDivElement { _prevClass: 'shade' },
  '3': HTMLDivElement { _prevClass: 'shade' } 
}

I don't know what _prevClass really represents, but if I change the selector from .querySelectorAll(".page") to .querySelectorAll(".shade") it actually returns all 4 divs still, so I assume its the class of the returned elements.

Changing the class of the first div added to the slot or removing it entirely results in the same thing (but different class in the output obviously).


It should be noted that the component works as expected when viewed in the browser. Run yarn run serve then click on MyComponent at the top of the page. Open the dev tools and you'll see the node lists written to the console.

@benm-eras
Copy link
Author

Thanks for the quick fix @eddyerburgh!!!!

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

No branches or pull requests

2 participants