import { describe, expect, test } from 'vitest';
import fs from 'fs';
import url from 'url';
import path from 'path';
import {
Document,
Page,
View,
Text,
ImageBackground,
} from '@react-pdf/renderer';
import renderToImage from './renderComponent';
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
const Orientation1 = fs.readFileSync(`${__dirname}/images/orientation-1.jpeg`);
const mount = async (children) => {
const image = await renderToImage(
{children}
,
);
return image;
};
describe('ImageBackground', () => {
test('should render image behind children', async () => {
const image = await mount(
Hello World
,
);
expect(image).toMatchImageSnapshot();
});
test('should render with nested views', async () => {
const image = await mount(
Overlay Content
,
);
expect(image).toMatchImageSnapshot();
});
test('should render with source prop', async () => {
const image = await mount(
Source Prop
,
);
expect(image).toMatchImageSnapshot();
});
test('should render without children', async () => {
const image = await mount(
,
);
expect(image).toMatchImageSnapshot();
});
});