Skip to content

Commit 010dafd

Browse files
leineveber5ZYSZ3K
authored andcommitted
test(transient-render-engine): snapshot nested inline whitespace
1 parent 5855a72 commit 010dafd

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

packages/transient-render-engine/src/flow/__tests__/__snapshots__/collapse.test.ts.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,18 @@ exports[`collapse function should not collapse when white-space CSS property is
140140
</TBlock>
141141
`;
142142
143+
exports[`collapse function should preserve boundary spaces wrapped in nested inline phrasing tags 1`] = `
144+
<TPhrasing tagName="span" nodeIndex={0}>
145+
<TPhrasing tagName="span" nodeIndex={0}>
146+
<TText tagName="strong" nodeIndex={0} data="foo" />
147+
<TText anonymous nodeIndex={1} data=" " />
148+
</TPhrasing>
149+
<TPhrasing tagName="span" nodeIndex={1}>
150+
<TText tagName="strong" nodeIndex={0} data="bar" />
151+
</TPhrasing>
152+
</TPhrasing>
153+
`;
154+
143155
exports[`collapse function should remove children from TPhrasing nodes which are empty after timming 1`] = `
144156
<TPhrasing anonymous nodeIndex={0}>
145157
<TText anonymous nodeIndex={0} data="Foo" />

packages/transient-render-engine/src/flow/__tests__/collapse.test.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@ describe('collapse function', () => {
4141
const ttree = makeTTree(
4242
'<span><span><strong>foo</strong> </span><span><strong>bar</strong></span></span>'
4343
);
44-
const [firstSpan, secondSpan] = ttree.children;
45-
expect(firstSpan.tagName).toBe('span');
46-
expect(firstSpan.children).toHaveLength(2);
47-
expect((firstSpan.children[0] as TTextImpl).data).toBe('foo');
48-
expect((firstSpan.children[1] as TTextImpl).data).toBe(' ');
49-
expect(secondSpan.tagName).toBe('span');
50-
expect(secondSpan.children).toHaveLength(1);
51-
expect((secondSpan.children[0] as TTextImpl).data).toBe('bar');
44+
expect(ttree).toMatchSnapshot();
45+
});
46+
it('should collapse consecutive boundary spaces wrapped in nested inline phrasing tags', () => {
47+
const twoSpaces = makeTTree(
48+
'<span><span><strong>foo</strong> </span><span><strong>bar</strong></span></span>'
49+
);
50+
const oneSpace = makeTTree(
51+
'<span><span><strong>foo</strong> </span><span><strong>bar</strong></span></span>'
52+
);
53+
expect(twoSpaces).toEqual(oneSpace);
5254
});
5355
it('should handle nested anchors', () => {
5456
const ttree = makeTTree(nestedHyperlinksSource);

0 commit comments

Comments
 (0)