Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/layout/src/node/getWrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const getWrap = (node: SafeNode) => {

if (!node.props) return true;

return 'wrap' in node.props ? node.props.wrap : true;
return 'wrap' in node.props && node.props.wrap != null
? node.props.wrap
: true;
};

export default getWrap;
68 changes: 68 additions & 0 deletions packages/layout/tests/node/getWrap.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { describe, expect, test } from 'vitest';

import getWrap from '../../src/node/getWrap';

describe('node getWrap', () => {
test('Should return false by default for non-wrap types', () => {
const svgResult = getWrap({ type: 'SVG', props: {}, style: {} });
expect(svgResult).toBe(false);

const noteResult = getWrap({ type: 'NOTE', props: {}, style: {} });
expect(noteResult).toBe(false);

const imageResult = getWrap({
type: 'IMAGE',
props: { src: '' },
style: {},
});
expect(imageResult).toBe(false);

const canvasResult = getWrap({
type: 'CANVAS',
props: { paint: () => null },
style: {},
});
expect(canvasResult).toBe(false);
});

test('Should return true by default for other types', () => {
const viewResult = getWrap({ type: 'VIEW', props: {}, style: {} });
expect(viewResult).toBe(true);

const textResult = getWrap({ type: 'TEXT', props: {}, style: {} });
expect(textResult).toBe(true);
});

test('Should return true if wrap value is null or undefined', () => {
const undefinedResult = getWrap({
type: 'VIEW',
props: { wrap: undefined },
style: {},
});
expect(undefinedResult).toBe(true);

// @ts-expect-error Deliberately testing an invalid case to ensure it's also handled gracefully
const nullResult = getWrap({
type: 'VIEW',
props: { wrap: null },
style: {},
});
expect(nullResult).toBe(true);
});

test('Should return the custom wrap value if provided', () => {
const trueResult = getWrap({
type: 'VIEW',
props: { wrap: true },
style: {},
});
expect(trueResult).toBe(true);

const falseResult = getWrap({
type: 'VIEW',
props: { wrap: false },
style: {},
});
expect(falseResult).toBe(false);
});
});