1+ import '@testing-library/jest-dom/extend-expect'
12import { Component , h } from 'preact'
2-
3- import { render , waitFor } from '..' // eslint-disable-line import/named
3+ import { screen , render , waitForElementToBeRemoved } from '..'
44
55const fetchAMessage = ( ) => new Promise ( ( resolve ) => {
66 // we are using random timeout here to simulate a real-time example
@@ -15,15 +15,15 @@ const fetchAMessage = () => new Promise((resolve) => {
1515class ComponentWithLoader extends Component {
1616 state = { loading : true }
1717
18- async componentDidMount ( ) {
19- const data = await fetchAMessage ( )
20-
21- this . setState ( { data , loading : false } ) // eslint-disable-line
18+ componentDidMount ( ) {
19+ fetchAMessage ( ) . then ( data => {
20+ this . setState ( { data , loading : false } )
21+ } )
2222 }
2323
2424 render ( ) {
2525 if ( this . state . loading ) {
26- return < div > Loading...</ div >
26+ return ( < div > Loading...</ div > )
2727 }
2828
2929 return (
@@ -35,11 +35,8 @@ class ComponentWithLoader extends Component {
3535}
3636
3737test ( 'it waits for the data to be loaded' , async ( ) => {
38- const { queryByText, queryByTestId } = render ( < ComponentWithLoader /> )
39-
40- expect ( queryByText ( 'Loading...' ) ) . toBeTruthy ( )
41-
42- await waitFor ( ( ) => expect ( queryByText ( 'Loading...' ) ) . toBeNull ( ) )
43-
44- expect ( queryByTestId ( 'message' ) . textContent ) . toMatch ( / H e l l o W o r l d / )
38+ render ( < ComponentWithLoader /> )
39+ const loading = ( ) => screen . getByText ( 'Loading...' )
40+ await waitForElementToBeRemoved ( loading )
41+ expect ( screen . getByTestId ( 'message' ) ) . toHaveTextContent ( / H e l l o W o r l d / )
4542} )
0 commit comments