-
Notifications
You must be signed in to change notification settings - Fork 794
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
Jest fails when using this.el.querySelectorAll(':scope > *') #2444
Comments
I saw the same thing with the disjunction query:
But not with I think the issue is with the Sizzle query library: |
yep, unfortunately stencil uses sizzle under the hood, in the meantime, you can use:
to workaround this issue |
I think this should be reopened. Having specific test logic in production code is a pretty ugly code wart in my opinion. Also how are we supposed to test components that rely on the Have you considered swapping out sizzle for another library or a polyfill that implements an up to date standard? |
Note this is how I’m getting around this issue: import { Build } from '@stencil/core';
// ...
const items = Build.isTesting
? Array.from(this.el.children).filter((el) =>
el.matches('my-component-a, my-component-b'),
)
: this.el.querySelectorAll(
':scope > my-component-a, :scope > my-component-b',
);
items.forEach((item) => {
// Do stuff with item...
}); Note the dual logic, and the latter case is never tested in unit tests. So a type-o in the latter selector will never be detected in automated tests. |
Managed to get around this issue without having to add test logic inside of production code:
Still not the cleanest solution, but atleast we're not polluting our code! 👍 |
Stencil version:
I'm submitting a:
[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/
Current behavior:
Jest doesn't seem to understand scoped.
If I comment :scoped
![image](https://user-images.githubusercontent.com/3018441/82063862-0585b480-969a-11ea-9aae-5f02d5f67174.png)
Those same lines are not in error anymore.
Expected behavior:
I don't expect it to fail. When I was using these versions, I didn't have a problem
Steps to reproduce:
add this line in render:
Other information:
I have no idea if this is related to jest or stencil.
The text was updated successfully, but these errors were encountered: