bug: Test Function toEqualHtml does not work with disabled shadowdom and slots properly
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 42/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- typescript
Research direction
Reproduce the failure in src/components/test-with-slot/test/test-with-slot.spec.tsx using newSpecPage and toEqualHtml, then trace how the slot output is represented during comparison. Done means a component with shadow:false and a slot can be compared with toEqualHtml without the unexpected comment causing failure, with the documented behavior covered.
Written by the indexing model from the issue text.
Description
Prerequisites
- I have read the Contributing Guidelines.
- I agree to follow the Code of Conduct.
- I have searched for existing issues that already report this problem, without success.
Stencil Version
2.7.0
Current Behavior
Using a slot should not compromise a component's testability.
Currently using a slot (with shadow:false) causes unit tests to fail due to a HTML comment being inserted as it seems.
Removing the slot "fixes" the testcase (but makes it useless).
Expected Behavior
a) It is possible to use toEqualHtml to test a component with a slot and get proper error messages when test cases fail
b) it is documented
Steps to Reproduce
Following testcase should work (toEqualHtml should normalize whitespaces anyway, adding or removing whitespaces to expectation does not change result).
@Component({
tag: 'test-with-slot',
styleUrl: 'test-with-slot.css',
shadow: false,
})
export class TestWithSlot {
render() {
return (
<Host>
<slot></slot>
</Host>
);
}
/* OUTPUT:
- <test-with-slot></test-with-slot>
+ <test-with-slot>
+ </test-with-slot>
*/
it('should work as expected', async () => {
const page = await newSpecPage({
components: [TestWithSlot],
html: `<test-with-slot></test-with-slot>`,
});
expect(page.root).toEqualHtml(`
<test-with-slot>
</test-with-slot>
`);
});
Code Reproduction URL
Additional Information
Comparing "manually" via outerHTML reveals what looks like a HTML comment being inserted by the framework which causes the comparison to fail.
I suspect the issue described above being not visible due to "prettyprinting" HTML to the console which I suspect hides the HTML comment and therefore makes it look like the issue would be caused by whitespaces.
/* OUTPUT
- <test-with-slot></test-with-slot>
+ <test-with-slot>
+ <!---->
+ </test-with-slot>
*/
it('should work with manual comparison - fails', async () => {
const page = await newSpecPage({
components: [TestWithSlot],
html: `<test-with-slot></test-with-slot>`,
});
expect(page.root.outerHTML).toEqualHtml(`
<test-with-slot>
</test-with-slot>
`);
});
- Dominant language
- TypeScript
- Stars
- 13.1k
- Forks
- 855
- Avg merge
- 4h 7m
- Merged PRs (30d)
- 44
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from stenciljs/core
-
Stencil v5
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Stencil v5
Difficulty 4/5 3-5 days Newbie friendliness 55/100
-
Bug: Validated Stencil v5
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Feature: Want this? Upvote it!
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Feature: Want this? Upvote it!
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Similar issues
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
vercel/react-tweet#225 ·