@osimatic/helpers-js 1.5.2 → 1.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,8 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ */
1
4
  const { OpenStreetMap } = require('../open_street_map');
5
+ const L = require('leaflet');
2
6
 
3
7
  describe('OpenStreetMap', () => {
4
8
  describe('getUrl', () => {
@@ -299,21 +303,17 @@ describe('OpenStreetMap', () => {
299
303
  setZoom: jest.fn()
300
304
  };
301
305
 
302
- // Mock L.latLngBounds
303
- global.L = {
304
- latLngBounds: jest.fn((locations) => ({
305
- _bounds: locations
306
- }))
307
- };
308
-
309
306
  const locations = [[48.8566, 2.3522], [48.8606, 2.3376]];
307
+ const mockBounds = { _bounds: locations };
308
+ const latLngBoundsSpy = jest.spyOn(L, 'latLngBounds').mockReturnValue(mockBounds);
309
+
310
310
  OpenStreetMap.centerMapToLocations(mockMap, locations);
311
311
 
312
312
  expect(mockMap.invalidateSize).toHaveBeenCalledWith(false);
313
- expect(global.L.latLngBounds).toHaveBeenCalledWith(locations);
313
+ expect(latLngBoundsSpy).toHaveBeenCalledWith(locations);
314
314
  expect(mockMap.fitBounds).toHaveBeenCalled();
315
315
 
316
- delete global.L;
316
+ latLngBoundsSpy.mockRestore();
317
317
  });
318
318
 
319
319
  test('should not do anything when map is null', () => {
@@ -346,18 +346,14 @@ describe('OpenStreetMap', () => {
346
346
  setZoom: jest.fn()
347
347
  };
348
348
 
349
- global.L = {
350
- latLngBounds: jest.fn((locations) => ({
351
- _bounds: locations
352
- }))
353
- };
354
-
355
349
  const locations = [[48.8566, 2.3522]];
350
+ const latLngBoundsSpy = jest.spyOn(L, 'latLngBounds').mockReturnValue({ _bounds: locations });
351
+
356
352
  OpenStreetMap.centerMapToLocations(mockMap, locations, [20, 20], 18);
357
353
 
358
354
  expect(mockMap.setZoom).toHaveBeenCalledWith(18);
359
355
 
360
- delete global.L;
356
+ latLngBoundsSpy.mockRestore();
361
357
  });
362
358
 
363
359
  test('should use custom padding', () => {
@@ -368,13 +364,9 @@ describe('OpenStreetMap', () => {
368
364
  setZoom: jest.fn()
369
365
  };
370
366
 
371
- global.L = {
372
- latLngBounds: jest.fn((locations) => ({
373
- _bounds: locations
374
- }))
375
- };
376
-
377
367
  const locations = [[48.8566, 2.3522]];
368
+ const latLngBoundsSpy = jest.spyOn(L, 'latLngBounds').mockReturnValue({ _bounds: locations });
369
+
378
370
  OpenStreetMap.centerMapToLocations(mockMap, locations, [50, 50]);
379
371
 
380
372
  expect(mockMap.fitBounds).toHaveBeenCalledWith(
@@ -382,7 +374,7 @@ describe('OpenStreetMap', () => {
382
374
  { padding: [50, 50] }
383
375
  );
384
376
 
385
- delete global.L;
377
+ latLngBoundsSpy.mockRestore();
386
378
  });
387
379
  });
388
380
  });