2023-04-09 15:11:31 -07:00

29 lines
847 B
TypeScript

import { test, expect } from '@playwright/experimental-ct-react17';
import Button from '@/components/Button';
import DefaultChildren from '@/components/DefaultChildren';
test('execute callback when the button is clicked', async ({ mount }) => {
const messages: string[] = [];
const component = await mount(
<Button
title="Submit"
onClick={(data) => {
messages.push(data);
}}
></Button>
);
await component.click();
expect(messages).toEqual(['hello']);
});
test('execute callback when a child node is clicked', async ({ mount }) => {
let clickFired = false;
const component = await mount(
<DefaultChildren>
<span onClick={() => (clickFired = true)}>Main Content</span>
</DefaultChildren>
);
await component.getByText('Main Content').click();
expect(clickFired).toBeTruthy();
});