Skip to content

Commit cac1e3b

Browse files
committed
fix: undefined and null wrap prop values are rendered as undefined instead of true by default
1 parent ee5c96b commit cac1e3b

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

packages/layout/src/node/getWrap.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ const getWrap = (node: SafeNode) => {
88

99
if (!node.props) return true;
1010

11-
return 'wrap' in node.props ? node.props.wrap : true;
11+
return 'wrap' in node.props && node.props.wrap != null
12+
? node.props.wrap
13+
: true;
1214
};
1315

1416
export default getWrap;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { describe, expect, test } from 'vitest';
2+
3+
import getWrap from '../../src/node/getWrap';
4+
5+
describe('node getWrap', () => {
6+
test('Should return false by default for non-wrap types', () => {
7+
const svgResult = getWrap({ type: 'SVG', props: {}, style: {} });
8+
expect(svgResult).toBe(false);
9+
10+
const noteResult = getWrap({ type: 'NOTE', props: {}, style: {} });
11+
expect(noteResult).toBe(false);
12+
13+
const imageResult = getWrap({
14+
type: 'IMAGE',
15+
props: { src: '' },
16+
style: {},
17+
});
18+
expect(imageResult).toBe(false);
19+
20+
const canvasResult = getWrap({
21+
type: 'CANVAS',
22+
props: { paint: () => null },
23+
style: {},
24+
});
25+
expect(canvasResult).toBe(false);
26+
});
27+
28+
test('Should return true by default for other types', () => {
29+
const viewResult = getWrap({ type: 'VIEW', props: {}, style: {} });
30+
expect(viewResult).toBe(true);
31+
32+
const textResult = getWrap({ type: 'TEXT', props: {}, style: {} });
33+
expect(textResult).toBe(true);
34+
});
35+
36+
test('Should return true if wrap value is null or undefined', () => {
37+
const undefinedResult = getWrap({
38+
type: 'VIEW',
39+
props: { wrap: undefined },
40+
style: {},
41+
});
42+
expect(undefinedResult).toBe(true);
43+
44+
// @ts-expect-error Deliberately testing an invalid case to ensure it's also handled gracefully
45+
const nullResult = getWrap({
46+
type: 'VIEW',
47+
props: { wrap: null },
48+
style: {},
49+
});
50+
expect(nullResult).toBe(true);
51+
});
52+
53+
test('Should return the custom wrap value if provided', () => {
54+
const trueResult = getWrap({
55+
type: 'VIEW',
56+
props: { wrap: true },
57+
style: {},
58+
});
59+
expect(trueResult).toBe(true);
60+
61+
const falseResult = getWrap({
62+
type: 'VIEW',
63+
props: { wrap: false },
64+
style: {},
65+
});
66+
expect(falseResult).toBe(false);
67+
});
68+
});

0 commit comments

Comments
 (0)