File tree Expand file tree Collapse file tree
static/js/publisher/utils/__tests__ Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import {
2+ render ,
3+ screen ,
4+ act ,
5+ waitForElementToBeRemoved ,
6+ } from "@testing-library/react" ;
7+ import "@testing-library/jest-dom" ;
8+
9+ import { importComponent } from "../importComponent" ;
10+
11+ function renderComponent ( ) {
12+ const sleep = ( n : number ) => new Promise < void > ( ( r ) => setTimeout ( r , n ) ) ;
13+
14+ function MockComponent ( ) {
15+ return < h1 > Mock Component!</ h1 > ;
16+ }
17+
18+ const LazyComponent = importComponent ( async ( ) => {
19+ await sleep ( 100 ) ;
20+
21+ return {
22+ default : MockComponent ,
23+ } ;
24+ } ) ;
25+
26+ return render ( < LazyComponent /> ) ;
27+ }
28+
29+ describe ( "importComponent" , ( ) => {
30+ test ( "renders loader" , ( ) => {
31+ act ( ( ) => {
32+ renderComponent ( ) ;
33+ } ) ;
34+
35+ expect ( screen . getByText ( / L o a d i n g / ) ) . toBeInTheDocument ( ) ;
36+ } ) ;
37+
38+ test ( "renders component" , async ( ) => {
39+ await act ( async ( ) => {
40+ renderComponent ( ) ;
41+ } ) ;
42+
43+ await waitForElementToBeRemoved ( ( ) => screen . getByText ( / L o a d i n g / ) ) ;
44+
45+ expect ( screen . getByText ( / M o c k C o m p o n e n t ! / ) ) . toBeInTheDocument ( ) ;
46+ } ) ;
47+ } ) ;
You can’t perform that action at this time.
0 commit comments