1
+ import { lazy } from 'react' ;
2
+
1
3
import { render , screen } from 'sentry-test/reactTestingLibrary' ;
2
4
3
5
import LazyLoad from 'sentry/components/lazyLoad' ;
@@ -15,7 +17,6 @@ function BarComponent({}: TestProps) {
15
17
}
16
18
17
19
type ResolvedComponent = { default : React . ComponentType < TestProps > } ;
18
- type GetComponent = ( ) => Promise < ResolvedComponent > ;
19
20
20
21
describe ( 'LazyLoad' , function ( ) {
21
22
afterEach ( ( ) => {
@@ -25,7 +26,7 @@ describe('LazyLoad', function () {
25
26
it ( 'renders with a loading indicator when promise is not resolved yet' , function ( ) {
26
27
const importTest = new Promise < ResolvedComponent > ( ( ) => { } ) ;
27
28
const getComponent = ( ) => importTest ;
28
- render ( < LazyLoad component = { getComponent } /> ) ;
29
+ render ( < LazyLoad LazyComponent = { lazy ( getComponent ) } /> ) ;
29
30
30
31
// Should be loading
31
32
expect ( screen . getByTestId ( 'loading-indicator' ) ) . toBeInTheDocument ( ) ;
@@ -37,7 +38,7 @@ describe('LazyLoad', function () {
37
38
doResolve = resolve ;
38
39
} ) ;
39
40
40
- render ( < LazyLoad component = { ( ) => importFoo } /> ) ;
41
+ render ( < LazyLoad LazyComponent = { lazy ( ( ) => importFoo ) } /> ) ;
41
42
42
43
// Should be loading
43
44
expect ( screen . getByTestId ( 'loading-indicator' ) ) . toBeInTheDocument ( ) ;
@@ -58,7 +59,7 @@ describe('LazyLoad', function () {
58
59
) ;
59
60
60
61
try {
61
- render ( < LazyLoad component = { getComponent } /> ) ;
62
+ render ( < LazyLoad LazyComponent = { lazy ( getComponent ) } /> ) ;
62
63
} catch ( err ) {
63
64
// ignore
64
65
}
@@ -78,7 +79,7 @@ describe('LazyLoad', function () {
78
79
} ) ;
79
80
80
81
// First render Foo
81
- const { rerender} = render ( < LazyLoad component = { ( ) => importFoo } /> ) ;
82
+ const { rerender} = render ( < LazyLoad LazyComponent = { lazy ( ( ) => importFoo ) } /> ) ;
82
83
expect ( screen . getByTestId ( 'loading-indicator' ) ) . toBeInTheDocument ( ) ;
83
84
84
85
// resolve with foo
@@ -90,22 +91,21 @@ describe('LazyLoad', function () {
90
91
doResolve = resolve ;
91
92
} ) ;
92
93
93
- rerender ( < LazyLoad component = { ( ) => importBar } /> ) ;
94
+ rerender ( < LazyLoad LazyComponent = { lazy ( ( ) => importBar ) } /> ) ;
94
95
expect ( screen . getByTestId ( 'loading-indicator' ) ) . toBeInTheDocument ( ) ;
95
96
96
97
// resolve with bar
97
98
doResolve ! ( { default : BarComponent } ) ;
98
99
expect ( await screen . findByText ( 'my bar component' ) ) . toBeInTheDocument ( ) ;
99
100
100
101
// Update component prop to a mock to make sure it isn't re-called
101
- const getComponent2 : GetComponent = jest . fn (
102
- ( ) => new Promise < ResolvedComponent > ( ( ) => { } )
103
- ) ;
104
- rerender ( < LazyLoad component = { getComponent2 } /> ) ;
102
+ const getComponent2 = jest . fn ( ( ) => new Promise < ResolvedComponent > ( ( ) => { } ) ) ;
103
+ const LazyGet = lazy ( getComponent2 ) ;
104
+ rerender ( < LazyLoad LazyComponent = { LazyGet } /> ) ;
105
105
expect ( getComponent2 ) . toHaveBeenCalledTimes ( 1 ) ;
106
106
107
107
// Does not refetch on other prop changes
108
- rerender ( < LazyLoad component = { getComponent2 } testProp /> ) ;
108
+ rerender ( < LazyLoad LazyComponent = { LazyGet } testProp /> ) ;
109
109
expect ( getComponent2 ) . toHaveBeenCalledTimes ( 1 ) ;
110
110
} ) ;
111
111
} ) ;
0 commit comments