test(ct): solid callbacks (#16837)

This commit is contained in:
sand4rt 2022-08-25 22:02:55 +02:00 committed by GitHub
parent 3b1af7d75d
commit a0f19a4f2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -1,6 +1,7 @@
type ButtonProps = {
title: string;
onClick?(props: string): void;
}
export default function Button(props: ButtonProps) {
return <button>{props.title}</button>
return <button onClick={() => props.onClick?.('hello')}>{props.title}</button>
}

View File

@ -7,3 +7,12 @@ test('props should work', async ({ mount }) => {
const component = await mount(<Button title="Submit" />);
await expect(component).toContainText('Submit');
});
test('callback should work', 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'])
})