test(ct): solid callbacks (#16837)
This commit is contained in:
parent
3b1af7d75d
commit
a0f19a4f2d
|
|
@ -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>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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'])
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue