Skip to content

How to test click button #53

Closed
Closed
@marlonmleite

Description

@marlonmleite

The documentation is very simple and with few examples.

All of the click examples I saw, none clicks to see if the function is being called.

How to do this?

I try this, but isn't work:

import { act, fireEvent, render } from '@testing-library/svelte';
import Button from '../Button.svelte';

describe('Button', () => {
  test('should click button', async () => {
    const click = jest.fn();
    const { container } = render(Button, { props: { click } });
    const button = container.querySelector('button');

    const acting = act(() => {
      fireEvent.click(button);
    });

    await acting;

    expect(click).toBeCalled();

  });
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions