Skip to content

Commit 9d91b0f

Browse files
committed
update tests and read me
1 parent 720f6f1 commit 9d91b0f

File tree

4 files changed

+32
-28
lines changed

4 files changed

+32
-28
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
React Flickity Component
22
=======================
33

4-
[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
5-
64
# Introduction:
75
A React.js Flickity component.
86

@@ -16,6 +14,9 @@ npm install react-flickity-component
1614

1715
# Usage:
1816

17+
## V5 Updates
18+
V5 supports react v19 and above.
19+
1920
## V4 Updates
2021
V4 only supports react v18 and above. V4 also comes with an esmodule bundle format to support modern frontend tooling like vite.
2122
If you are staying on react v16, please keep using v3.

__tests__/component.spec.jsx

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,60 @@ import {it, expect, vi, afterEach } from 'vitest';
33
import { render, cleanup, screen, waitFor } from '@testing-library/react';
44
import Flickity from '../src';
55

6-
afterEach(() => {
6+
afterEach(async () => {
7+
await new Promise(resolve => setTimeout(resolve, 0));
78
cleanup();
89
});
910

1011

11-
it('Calls render and componentDidMount', () => {
12-
const componentDidMountSpy = vi.spyOn(Flickity.prototype, 'componentDidMount');
13-
const renderSpy = vi.spyOn(Flickity.prototype, 'render');
14-
15-
render(<Flickity/>);
16-
17-
expect(componentDidMountSpy).toHaveBeenCalledOnce();
18-
expect(renderSpy).toHaveBeenCalled();
12+
it('Renders component successfully', async () => {
13+
const { container } = render(<Flickity/>);
14+
15+
await waitFor(() => {
16+
expect(container.firstChild).toBeTruthy();
17+
});
18+
19+
expect(container.firstChild).toBeInstanceOf(HTMLElement);
1920
});
2021

2122
it('Renders children', async () => {
22-
const { getAllByAltText } = render(
23+
const { getAllByAltText, unmount, container } = render(
2324
<Flickity>
2425
<img src="/images/placeholder.png" alt="children"/>
2526
<img src="/images/placeholder.png" alt="children"/>
2627
<img src="/images/placeholder.png" alt="children"/>
2728
</Flickity>
2829
);
30+
31+
await waitFor(() => {
32+
expect(container.firstChild).toBeTruthy();
33+
});
2934

3035
await waitFor(() => expect(getAllByAltText('children').length).toEqual(3));
36+
unmount();
3137
});
3238

33-
it('Renders a static carousel', () => {
34-
const { getAllByAltText, rerender } = render(
39+
it('Renders a static carousel', async () => {
40+
const { getAllByAltText, unmount } = render(
3541
<Flickity static>
3642
<img src="/images/placeholder.png" alt="children"/>
3743
<img src="/images/placeholder.png" alt="children"/>
3844
</Flickity>
3945
);
4046

41-
expect(getAllByAltText('children').length).toEqual(2);
42-
})
47+
await waitFor(() => expect(getAllByAltText('children').length).toEqual(2));
48+
unmount();
49+
});
4350

44-
it('Reload carousel even it\'s static', () => {
45-
const { getAllByAltText, rerender } = render(
51+
it('Reload carousel even it\'s static', async () => {
52+
const { getAllByAltText, rerender, unmount } = render(
4653
<Flickity static reloadOnUpdate>
4754
<img src="/images/placeholder.png" alt="children"/>
4855
<img src="/images/placeholder.png" alt="children"/>
4956
</Flickity>
5057
);
5158

52-
expect(getAllByAltText('children').length).toEqual(2);
59+
await waitFor(() => expect(getAllByAltText('children').length).toEqual(2));
5360

5461
rerender(
5562
<Flickity static reloadOnUpdate>
@@ -58,5 +65,7 @@ it('Reload carousel even it\'s static', () => {
5865
<img src="/images/placeholder.png" alt="children"/>
5966
</Flickity>
6067
);
61-
expect(getAllByAltText('children').length).toEqual(3);
62-
})
68+
69+
await waitFor(() => expect(getAllByAltText('children').length).toEqual(3));
70+
unmount();
71+
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-flickity-component",
3-
"version": "4.0.7",
3+
"version": "5.0.0",
44
"description": "react flickity component",
55
"files": [
66
"dist"

src/index.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,6 @@ class FlickityComponent extends Component<ReactFlickityComponentProps, FlickityC
115115
}
116116
}
117117

118-
componentWillUnmount() {
119-
if (this.flkty) {
120-
this.flkty.destroy();
121-
}
122-
}
123-
124118
setReady() {
125119
if (this.state.flickityReady) return;
126120
const setFlickityToReady = () => this.setState({ flickityReady: true });

0 commit comments

Comments
 (0)