@@ -8,12 +8,13 @@ import { MapContainer, useMapEvents } from "react-leaflet";
88import ResetViewControl from "../src/ResetViewControl" ;
99
1010import type { ResetViewControlOptions } from "../src/ResetViewControl" ;
11- import type { LatLngExpression , Map } from "leaflet" ;
11+ import { LatLng } from "leaflet" ;
12+ import type { Map } from "leaflet" ;
1213
1314describe ( "ResetViewControl" , ( ) => {
1415 const mockHandleViewReset = jest . fn ( ) ;
1516 let mapInstance = null as Map | null
16- const defaultMapCenter = [ - 96.8716348 , 32.8205866 ] as LatLngExpression ;
17+ const defaultMapCenter = new LatLng ( - 96.8716348 , 32.8205866 ) ;
1718 const defaultMapZoom = 5
1819
1920 const ControlWrapper = ( { title, icon, centerToReset, zoomToReset } : ResetViewControlOptions ) => {
@@ -40,38 +41,38 @@ describe("ResetViewControl", () => {
4041
4142 test ( "can reset map view" , ( ) => {
4243 render ( < Map /> ) ;
43- expect ( mapInstance ?. getCenter ( ) . lat ) . toBeCloseTo ( defaultMapCenter [ 0 ] , 1 ) ;
44- expect ( mapInstance ?. getCenter ( ) . lng ) . toBeCloseTo ( defaultMapCenter [ 1 ] , 1 ) ;
44+ expect ( mapInstance ?. getCenter ( ) . lat ) . toBeCloseTo ( defaultMapCenter . lat , 1 ) ;
45+ expect ( mapInstance ?. getCenter ( ) . lng ) . toBeCloseTo ( defaultMapCenter . lng , 1 ) ;
4546 expect ( mapInstance ?. getZoom ( ) ) . toEqual ( defaultMapZoom )
4647
47- mapInstance ?. setView ( [ 2 , 46 ] , 6 )
48+ mapInstance ?. setView ( new LatLng ( 2 , 46 ) , 6 )
4849
4950 expect ( mapInstance ?. getCenter ( ) . lat ) . toBeCloseTo ( 2 , 1 ) ;
5051 expect ( mapInstance ?. getCenter ( ) . lng ) . toBeCloseTo ( 46 , 1 ) ;
5152 expect ( mapInstance ?. getZoom ( ) ) . toEqual ( 6 )
5253
5354 userEvent . click ( screen . getByTitle ( "Reset view" ) ) ;
5455
55- expect ( mapInstance ?. getCenter ( ) . lat ) . toBeCloseTo ( defaultMapCenter [ 0 ] , 1 ) ;
56- expect ( mapInstance ?. getCenter ( ) . lng ) . toBeCloseTo ( defaultMapCenter [ 1 ] , 1 ) ;
56+ expect ( mapInstance ?. getCenter ( ) . lat ) . toBeCloseTo ( defaultMapCenter . lat , 1 ) ;
57+ expect ( mapInstance ?. getCenter ( ) . lng ) . toBeCloseTo ( defaultMapCenter . lng , 1 ) ;
5758 expect ( mapInstance ?. getZoom ( ) ) . toEqual ( defaultMapZoom )
5859
5960 expect ( mockHandleViewReset ) . toHaveBeenCalledTimes ( 2 ) ;
6061 } ) ;
6162
6263 test ( "can reset the map view to a zoom and center different from those mounted by the map" , ( ) => {
63- const centerToReset = [ 44.8 , 6.3 ] as LatLngExpression ;
64+ const centerToReset = new LatLng ( 44.8 , 6.3 ) ;
6465 const zoomToReset = 17 ;
6566 render ( < Map centerToReset = { centerToReset } zoomToReset = { zoomToReset } /> ) ;
6667
67- expect ( mapInstance ?. getCenter ( ) . lat ) . toBeCloseTo ( defaultMapCenter [ 0 ] , 1 ) ;
68- expect ( mapInstance ?. getCenter ( ) . lng ) . toBeCloseTo ( defaultMapCenter [ 1 ] , 1 ) ;
68+ expect ( mapInstance ?. getCenter ( ) . lat ) . toBeCloseTo ( defaultMapCenter . lat , 1 ) ;
69+ expect ( mapInstance ?. getCenter ( ) . lng ) . toBeCloseTo ( defaultMapCenter . lng , 1 ) ;
6970 expect ( mapInstance ?. getZoom ( ) ) . toEqual ( defaultMapZoom )
7071
7172 userEvent . click ( screen . getByTitle ( "Reset view" ) ) ;
7273
73- expect ( mapInstance ?. getCenter ( ) . lat ) . toBeCloseTo ( centerToReset [ 0 ] , 1 ) ;
74- expect ( mapInstance ?. getCenter ( ) . lng ) . toBeCloseTo ( centerToReset [ 1 ] , 1 ) ;
74+ expect ( mapInstance ?. getCenter ( ) . lat ) . toBeCloseTo ( centerToReset . lat , 1 ) ;
75+ expect ( mapInstance ?. getCenter ( ) . lng ) . toBeCloseTo ( centerToReset . lng , 1 ) ;
7576 expect ( mapInstance ?. getZoom ( ) ) . toEqual ( zoomToReset )
7677
7778 expect ( mockHandleViewReset ) . toHaveBeenCalledTimes ( 3 ) ;
0 commit comments