1
1
import { render } from '@testing-library/react'
2
- import { type LatLngExpression , Map } from 'leaflet'
2
+ import { type LatLngExpression , Map as LeafletMap } from 'leaflet'
3
3
import React , { StrictMode , useEffect , useRef } from 'react'
4
4
5
5
import { MapContainer , useMap } from '../src'
@@ -30,10 +30,15 @@ describe('MapContainer', () => {
30
30
31
31
describe ( 'provides the Map instance' , ( ) => {
32
32
test ( 'with the useMap() hook' , ( done ) => {
33
+ let doneCalled = false
34
+
33
35
function TestChild ( ) {
34
36
const map = useMap ( )
35
- expect ( map ) . toBeInstanceOf ( Map )
36
- done ( )
37
+ expect ( map ) . toBeInstanceOf ( LeafletMap )
38
+ if ( ! doneCalled ) {
39
+ doneCalled = true
40
+ done ( )
41
+ }
37
42
return null
38
43
}
39
44
@@ -49,10 +54,15 @@ describe('MapContainer', () => {
49
54
} )
50
55
51
56
test ( 'in the ref function' , ( done ) => {
57
+ let doneCalled = false
58
+
52
59
const ref = ( map ) => {
53
- if ( map !== null ) {
54
- expect ( map ) . toBeInstanceOf ( Map )
55
- done ( )
60
+ if ( map != null ) {
61
+ expect ( map ) . toBeInstanceOf ( LeafletMap )
62
+ if ( ! doneCalled ) {
63
+ doneCalled = true
64
+ done ( )
65
+ }
56
66
}
57
67
}
58
68
@@ -64,14 +74,19 @@ describe('MapContainer', () => {
64
74
} )
65
75
66
76
test ( 'in the ref object' , ( done ) => {
77
+ let doneCalled = false
78
+
67
79
function Wrapper ( ) {
68
- const ref = useRef ( )
80
+ const ref = useRef ( undefined )
69
81
70
82
useEffect ( ( ) => {
71
83
setTimeout ( ( ) => {
72
- if ( ref . current !== null ) {
73
- expect ( ref . current ) . toBeInstanceOf ( Map )
74
- done ( )
84
+ if ( ref . current != null ) {
85
+ expect ( ref . current ) . toBeInstanceOf ( LeafletMap )
86
+ if ( ! doneCalled ) {
87
+ doneCalled = true
88
+ done ( )
89
+ }
75
90
}
76
91
} , 50 )
77
92
} , [ ] )
@@ -86,12 +101,16 @@ describe('MapContainer', () => {
86
101
test ( 'sets center and zoom props' , ( done ) => {
87
102
const center : LatLngExpression = [ 1.2 , 3.4 ]
88
103
const zoom = 10
104
+ let doneCalled = false
89
105
90
106
const ref = ( map ) => {
91
- if ( map !== null ) {
107
+ if ( map != null ) {
92
108
expect ( map . getCenter ( ) ) . toEqual ( { lat : 1.2 , lng : 3.4 } )
93
109
expect ( map . getZoom ( ) ) . toBe ( zoom )
94
- done ( )
110
+ if ( ! doneCalled ) {
111
+ doneCalled = true
112
+ done ( )
113
+ }
95
114
}
96
115
}
97
116
0 commit comments