@@ -61,6 +61,36 @@ test('GeolocateControl error event', async () => {
6161 } ) ;
6262} ) ;
6363
64+ test ( 'GeolocateControl error event includes GeolocationPositionError constants' , async ( ) => {
65+ const map = createMap ( ) ;
66+ const geolocate = new GeolocateControl ( ) ;
67+ map . addControl ( geolocate ) ;
68+
69+ // Directly call _onError with a mock GeolocationPositionError to test
70+ // that PERMISSION_DENIED, POSITION_UNAVAILABLE, and TIMEOUT are passed through.
71+ // The mock-geolocation library doesn't support these constants.
72+ const mockError = {
73+ PERMISSION_DENIED : 1 ,
74+ POSITION_UNAVAILABLE : 2 ,
75+ TIMEOUT : 3 ,
76+ code : 1 ,
77+ message : 'User denied Geolocation' ,
78+ } as const satisfies GeolocationPositionError ;
79+
80+ await afterUIChanges ( ( resolve ) => {
81+ geolocate . on ( 'error' , ( error ) => {
82+ expect ( error . code ) . toEqual ( 1 ) ;
83+ expect ( error . message ) . toEqual ( 'User denied Geolocation' ) ;
84+ expect ( error . PERMISSION_DENIED ) . toEqual ( 1 ) ;
85+ expect ( error . POSITION_UNAVAILABLE ) . toEqual ( 2 ) ;
86+ expect ( error . TIMEOUT ) . toEqual ( 3 ) ;
87+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
88+ resolve ( ) ;
89+ } ) ;
90+ geolocate . _onError ( mockError ) ;
91+ } ) ;
92+ } ) ;
93+
6494test ( 'GeolocateControl outofmaxbounds event in active lock state' , async ( ) => {
6595 const map = createMap ( ) ;
6696 const geolocate = new GeolocateControl ( ) ;
0 commit comments