Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
wmertens committed Oct 11, 2024
1 parent 9738732 commit a8c0ec8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
13 changes: 6 additions & 7 deletions packages/qwik/src/core/tests/projection.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { HTML_NS, SVG_NS } from '../shared/utils/markers';
import { cleanupAttrs } from 'packages/qwik/src/testing/element-fixture';
import { DomFragment } from '../../testing/rendering.unit-util';

const DEBUG = false;
const DEBUG = !false;

/**
* Below are helper components that are constant. They have to be in the top level scope so that the
Expand All @@ -43,6 +43,8 @@ describe.each([
{ render: ssrRenderToDom }, //
{ render: domRender }, //
])('$render.name: projection', ({ render }) => {
const isSsr = render === ssrRenderToDom;

it('should render basic projection', async () => {
const Child = component$(() => {
return (
Expand Down Expand Up @@ -72,7 +74,7 @@ describe.each([
render
);
});
it('should render unused projection into template', async () => {
it.only('should render unused projection into template', async () => {
const Child = component$(() => {
return <span>no-projection</span>;
});
Expand All @@ -87,12 +89,9 @@ describe.each([
</DomFragment>
</DomFragment>
);
if (render === ssrRenderToDom) {
if (isSsr) {
expect(vnode_getNextSibling(vNode!)).toMatchVDOM(
<q:template style="display:none">
<DomFragment>parent-content</DomFragment>
<DomFragment>render-content</DomFragment>
</q:template>
<q:template style="display:none">parent-contentrender-content</q:template>
);
}
});
Expand Down
31 changes: 24 additions & 7 deletions packages/qwik/src/testing/vdom-diff.unit-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function diffJsxVNode(
if (expectedChildren.length === 1) {
return diffJsxVNode(received, expectedChildren[0], path, isSsr);
} else {
// We're skipping non-serialized vnodes, so they should have only one child
console.error('Expected fragment to have only one child', received, expected);
}
}
Expand Down Expand Up @@ -153,13 +154,29 @@ function diffJsxVNode(
diffs.push(...diffJsxVNode(receivedChild, expectedChild, path, isSsr));
}
} else {
diffs.push(
`${path.join(' > ')} expecting ${expectedChildren.length} children but was ${
receivedChildren.length
}`
);
diffs.push('EXPECTED', jsxToHTML(expected, ' '));
diffs.push('RECEIVED:', vnodeToHTML(received, ' '));
// special case: adjacent text nodes that are merged during SSR
if (isSsr && receivedChildren.length === 1 && vnode_isTextVNode(received)) {
// If the expected children are text nodes, we can compare them directly
const expectedText = expectedChildren
.map((child) =>
typeof child === 'string' ? child : typeof child === 'object' ? child.children : ''
)
.join('');
const receivedText = vnode_getText(received as _TextVNode);
if (expectedText !== receivedText) {
diffs.push(path.join(' > '));
diffs.push('EXPECTED', JSON.stringify(expectedText));
diffs.push('RECEIVED:', JSON.stringify(receivedText));
}
} else {
diffs.push(
`${path.join(' > ')} expecting ${expectedChildren.length} children but was ${
receivedChildren.length
}`
);
diffs.push('EXPECTED', jsxToHTML(expected, ' '));
diffs.push('RECEIVED:', vnodeToHTML(received, ' '));
}
}
path.pop();
}
Expand Down

0 comments on commit a8c0ec8

Please sign in to comment.