@@ -3,53 +3,60 @@ import {it, expect, vi, afterEach } from 'vitest';
33import { render , cleanup , screen , waitFor } from '@testing-library/react' ;
44import 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
2122it ( '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+ } ) ;
0 commit comments