Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { getSlots } from './getSlots';
import type { Slot } from './types';
import { resolveShorthand } from './resolveShorthand';

describe('getSlots', () => {
type FooProps = { id?: string; children?: React.ReactNode };
Expand Down Expand Up @@ -126,6 +127,24 @@ describe('getSlots', () => {
});
});

it('can use slot children functions from resolveShorthand to replace default slot rendering', () => {
type Slots = {
root: Slot<'div'>;
icon: Slot<'a'>;
};
const renderFunction = (C: React.ElementType, p: {}) => <C {...p} />;
expect(
getSlots<Slots>({
components: { root: 'div', icon: Foo },
root: resolveShorthand({ as: 'div' }, { required: true }),
icon: resolveShorthand({ id: 'bar', children: renderFunction }),
}),
).toEqual({
slots: { root: 'div', icon: React.Fragment },
slotProps: { root: {}, icon: { children: <Foo id="bar" /> } },
});
});

it('can render a primitive input with no children', () => {
type Slots = {
root: Slot<'div'>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as React from 'react';
import { getSlotsNext } from './getSlotsNext';
import type { Slot } from './types';
import { resolveShorthand } from './resolveShorthand';
import { SLOT_RENDER_FUNCTION_SYMBOL } from './constants';

describe('getSlotsNext', () => {
type FooProps = { id?: string; children?: React.ReactNode };
Expand Down Expand Up @@ -127,6 +129,24 @@ describe('getSlotsNext', () => {
});
});

it('can use slot children functions from resolveShorthand to replace default slot rendering', () => {
type Slots = {
root: Slot<'div'>;
icon: Slot<'a'>;
};
const renderFunction = (C: React.ElementType, p: {}) => <C {...p} />;
expect(
getSlotsNext<Slots>({
components: { root: 'div', icon: Foo },
root: resolveShorthand({ as: 'div' }, { required: true }),
icon: resolveShorthand({ id: 'bar', children: renderFunction }),
}),
).toEqual({
slots: { root: 'div', icon: Foo },
slotProps: { root: {}, icon: { children: undefined, id: 'bar', [SLOT_RENDER_FUNCTION_SYMBOL]: renderFunction } },
});
});

it('can render a primitive input with no children', () => {
type Slots = {
root: Slot<'div'>;
Expand Down