import { render } from '@react-email/render';
import { mapReactTree } from './map-react-tree.js';
describe('mapReactTree()', () => {
it('process should be called for all normal elements', async () => {
const node = (
<>
This is a div
Interesting span
header 1
>
);
const process = vi.fn((n: React.ReactNode) => n);
const result = mapReactTree(node, process);
await render(<>{result}>);
expect(process).toHaveBeenCalledTimes(7);
});
it('process should be called for all elements with custom components', async () => {
const Custom = (props: { children: React.ReactNode }) => {
return (
<>
Testing heading
surrounded span
surrounded by div
{props.children}
>
);
};
const node = (
<>
This is a div
Interesting span
header 1
Well, hello friends!
>
);
const process = vi.fn((n: React.ReactNode) => n);
const result = mapReactTree(node, process);
await render(<>{result}>);
expect(process).toHaveBeenCalledTimes(17);
});
});