Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

repo showing a problem in `@testing-library/preact": "^3.2.2"`
https://github.com/rburgst/preact-testing-animation-bug

Last synced: 2 days ago
JSON representation

repo showing a problem in `@testing-library/preact": "^3.2.2"`

Awesome Lists containing this project

README

        

Sample repo that shows a problem where `fireEvent.animationEnd` does not work for a preact component.

See also https://github.com/testing-library/preact-testing-library/issues/67

To reproduce

```
yarn install
yarn test
```

Note that all tests are green

now change the version of `@testing-library/preact": "^3.2.2"`

```
yarn install
yarn test
```

Note that the test fails now.

## Details

The following does not work

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

export const TestComponent: FunctionComponent = ({
onNextClick,
}) => {
return (


FOO

);
};

```

and the corresponding test
```typescript

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

//when
const { container } = render();

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

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

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`.

Screenshot of the listeners in jsdoms `EventTarget-impl.js` `invokeEventListeners`
![img.png](doc/img.png)