Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fireEvent.animationEnd does not call preact-registered listener #67

Open
rburgst opened this issue Sep 14, 2022 · 1 comment
Open

fireEvent.animationEnd does not call preact-registered listener #67

rburgst opened this issue Sep 14, 2022 · 1 comment

Comments

@rburgst
Copy link

rburgst commented Sep 14, 2022

  • preact-testing-library version: 3.2.2
  • preact version: 10.11.0
  • node version: 16.17.0
  • npm (or yarn) version: yarn 3.2.3

Relevant code or config

export interface TestComponentProps {
  onNextClick?: () => void;
}

export const TestComponent: FunctionComponent<TestComponentProps> = ({
  onNextClick,
}) => {
  return (
    <div data-countdown onAnimationEnd={onNextClick}>
      FOO
    </div>
  );
};

and the corresponding test

  it("should call onNextClick on animation end", async () => {
    //given
    const props = {
      onNextClick: jest.fn(),
    };

    //when
    const { container } = render(<TestComponent {...props} />);

    fireEvent.animationEnd(
      container.querySelector("[data-countdown]") as HTMLElement
    );

    //then
    expect(props.onNextClick).toHaveBeenCalledTimes(1);
  });

What you did:

in a jest test calling

  const divElement = container.querySelector("[data-countdown]") as HTMLElement;
  fireEvent.animationEnd(divElement);

What happened:

The callback in

<div onAnimationEnd={onNextClick}>

is not being called.

The test will report the following


  ● test-component › should call onNextClick on animation end

    expect(jest.fn()).toHaveBeenCalledTimes(expected)

    Expected number of calls: 1
    Received number of calls: 0

      19 |
      20 |     //then
    > 21 |     expect(props.onNextClick).toHaveBeenCalledTimes(1);
         |                               ^
      22 |   });
      23 | });
      24 |

      at Object.<anonymous> (src/components/__tests__/test.spec.tsx:21:31)
      at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
      at runJest (node_modules/@jest/core/build/runJest.js:404:19)
      at _run10000 (node_modules/@jest/core/build/cli/index.js:320:7)
      at runCLI (node_modules/@jest/core/build/cli/index.js:173:3)

Reproduction repository:
https://github.com/rburgst/preact-testing-animation-bug/

Problem description:

The problem appears that the listeners in jsdom are registered with AnimationEnd while the event being fired is animationend.

Note that this worked in @testing-library/preact": "^2.0.1" but fails with the current version 3.2.2.

Suggested solution:

I guess this problem is similar to #51

@rburgst
Copy link
Author

rburgst commented Apr 20, 2023

anyone home?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant