Skip to content

Can not test fireEvent.touchStart side effects  #23

@jottaxwds

Description

@jottaxwds
  • preact-testing-library version: 1.0.2
  • preact version: 10.3.2
  • node version: 13.9.0
  • npm (or yarn) version: 6.13.7

Relevant code or config
Button.js

const Button = ({myHandler}) => (
    <button data-testid='my-button' onTouchStart={myHandler}>Click me</button>
)

export default Button;

Button.test.js

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

describe('Button behavior test:', () => {
   it('Should call myHandler on touchStart', () => {
        const mockFn = jest.fn();
        const { getByTestId } = render(<Button myHandler={mockFn} />);
        fireEvent.touchStart(getByTestId('my-button'));
        expect(mockFn).toHaveBeenCalled();
   });
});

What you did:
Simple button component with onTouchStart event that triggers a prop method.

What happened:
I can not test it due to fireEvent.touchStart is not triggering the event and not creating side effects on my component.

Problem description:
I need to unit test the side effects of onTouchStart / onTouchEnd events on my components.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions