Skip to content

Commit 214def9

Browse files
committed
Setup React 19 beta
1 parent a18438e commit 214def9

22 files changed

+174
-263
lines changed

package.json

+10-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"@swc/core": "^1.3.37",
1717
"@swc/jest": "^0.2.24",
1818
"@testing-library/react": "^15.0.5",
19-
"@testing-library/react-hooks": "^8.0.1",
2019
"@types/jest": "^29.4.0",
2120
"@types/leaflet": "^1.9.1",
2221
"@types/warning": "^3.0.0",
@@ -25,13 +24,20 @@
2524
"jest": "^29.4.3",
2625
"jest-environment-jsdom": "^29.4.3",
2726
"leaflet": "^1.9.3",
28-
"react": "^18.2.0",
29-
"react-dom": "^18.2.0",
30-
"react-test-renderer": "^18.2.0",
27+
"react": "beta",
28+
"react-dom": "beta",
3129
"ts-jest-resolver": "^2.0.0",
3230
"turbo": "^1.8.3",
3331
"typescript": "^5.4.5"
3432
},
33+
"pnpm": {
34+
"overrides": {
35+
"@types/react": "npm:types-react@beta",
36+
"@types/react-dom": "npm:types-react-dom@beta",
37+
"react": "beta",
38+
"react-dom": "beta"
39+
}
40+
},
3541
"jest": {
3642
"projects": [
3743
"<rootDir>/packages/*"
+10-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { renderHook } from '@testing-library/react-hooks'
1+
import { renderHook } from '@testing-library/react'
22

33
import { useAttribution } from '../src'
44

@@ -15,21 +15,21 @@ describe('attribution', () => {
1515
})
1616

1717
rerender({ attribution: 'foo' })
18-
expect(attributionControl.addAttribution).toBeCalledTimes(1)
19-
expect(attributionControl.removeAttribution).toBeCalledTimes(0)
18+
expect(attributionControl.addAttribution).toHaveBeenCalledTimes(1)
19+
expect(attributionControl.removeAttribution).toHaveBeenCalledTimes(0)
2020

2121
rerender({ attribution: 'foo' })
22-
expect(attributionControl.addAttribution).toBeCalledTimes(1)
23-
expect(attributionControl.removeAttribution).toBeCalledTimes(0)
22+
expect(attributionControl.addAttribution).toHaveBeenCalledTimes(1)
23+
expect(attributionControl.removeAttribution).toHaveBeenCalledTimes(0)
2424

2525
rerender({ attribution: 'bar' })
26-
expect(attributionControl.addAttribution).toBeCalledTimes(2)
27-
expect(attributionControl.addAttribution).toBeCalledWith('bar')
28-
expect(attributionControl.removeAttribution).toBeCalledTimes(1)
29-
expect(attributionControl.removeAttribution).toBeCalledWith('foo')
26+
expect(attributionControl.addAttribution).toHaveBeenCalledTimes(2)
27+
expect(attributionControl.addAttribution).toHaveBeenCalledWith('bar')
28+
expect(attributionControl.removeAttribution).toHaveBeenCalledTimes(1)
29+
expect(attributionControl.removeAttribution).toHaveBeenCalledWith('foo')
3030

3131
rerender({ attribution: null })
32-
expect(attributionControl.removeAttribution).toBeCalledTimes(2)
32+
expect(attributionControl.removeAttribution).toHaveBeenCalledTimes(2)
3333
expect(attributionControl.removeAttribution).toHaveBeenLastCalledWith('bar')
3434
})
3535
})

packages/core/__tests__/context.tsx

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
import { renderHook } from '@testing-library/react-hooks'
1+
import { renderHook } from '@testing-library/react'
22
import type { Map } from 'leaflet'
33
import React, { StrictMode, type ReactNode } from 'react'
44

5-
import {
6-
CONTEXT_VERSION,
7-
LeafletProvider,
8-
createLeafletContext,
9-
useLeafletContext,
10-
} from '../src'
5+
import { CONTEXT_VERSION, LeafletContext, createLeafletContext, useLeafletContext } from '../src'
116

127
export function createWrapper(context) {
138
return function Wrapper({ children }: { children: ReactNode }) {
149
return (
1510
<StrictMode>
16-
<LeafletProvider value={context}>{children}</LeafletProvider>
11+
<LeafletContext value={context}>{children}</LeafletContext>
1712
</StrictMode>
1813
)
1914
}
@@ -33,7 +28,7 @@ describe('context', () => {
3328
const { result } = renderHook(() => useLeafletContext())
3429
return result.current
3530
}).toThrow(
36-
'No context provided: useLeafletContext() can only be used in a descendant of <MapContainer>',
31+
'No context provided: useLeafletContext() can only be used in a descendant of <MapContainer>'
3732
)
3833
})
3934

packages/core/__tests__/control.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { renderHook } from '@testing-library/react-hooks'
1+
import { renderHook } from '@testing-library/react'
22

33
import { createControlHook, createElementHook } from '../src'
44

@@ -14,11 +14,11 @@ describe('control', () => {
1414
const useControl = createControlHook(useElement)
1515

1616
const { unmount } = renderHook(() => useControl({}), { wrapper })
17-
expect(instance.addTo).toBeCalledTimes(1)
18-
expect(instance.addTo).toBeCalledWith(context.map)
17+
expect(instance.addTo).toHaveBeenCalledTimes(1)
18+
expect(instance.addTo).toHaveBeenCalledWith(context.map)
1919

2020
unmount()
21-
expect(instance.remove).toBeCalledTimes(1)
21+
expect(instance.remove).toHaveBeenCalledTimes(1)
2222
})
2323

2424
test('useLeafletControl() updates the position', () => {
@@ -35,10 +35,10 @@ describe('control', () => {
3535
wrapper: createWrapper({ map: true }),
3636
})
3737
rerender({ position: 'topleft' })
38-
expect(instance.setPosition).toBeCalledTimes(0)
38+
expect(instance.setPosition).toHaveBeenCalledTimes(0)
3939

4040
rerender({ position: 'topright' })
41-
expect(instance.setPosition).toBeCalledTimes(1)
42-
expect(instance.setPosition).toBeCalledWith('topright')
41+
expect(instance.setPosition).toHaveBeenCalledTimes(1)
42+
expect(instance.setPosition).toHaveBeenCalledWith('topright')
4343
})
4444
})

packages/core/__tests__/element.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { renderHook } from '@testing-library/react-hooks'
1+
import { renderHook } from '@testing-library/react'
22

33
import { createElementHook } from '../src'
44

@@ -11,8 +11,8 @@ describe('element', () => {
1111
const useElement = createElementHook(createElementMock)
1212
renderHook(() => useElement(props, context))
1313

14-
expect(createElementMock).toBeCalledTimes(1)
15-
expect(createElementMock).toBeCalledWith(props, context)
14+
expect(createElementMock).toHaveBeenCalledTimes(1)
15+
expect(createElementMock).toHaveBeenCalledWith(props, context)
1616
})
1717

1818
test('calls the element update function', () => {
@@ -25,20 +25,20 @@ describe('element', () => {
2525
const { rerender } = renderHook((p) => useElement(p, context), {
2626
initialProps: { test: true },
2727
})
28-
expect(createElementMock).toBeCalledTimes(1)
29-
expect(updateElementMock).toBeCalledTimes(0)
28+
expect(createElementMock).toHaveBeenCalledTimes(1)
29+
expect(updateElementMock).toHaveBeenCalledTimes(0)
3030

3131
rerender({ test: false })
32-
expect(updateElementMock).toBeCalledTimes(1)
33-
expect(updateElementMock).toBeCalledWith(
32+
expect(updateElementMock).toHaveBeenCalledTimes(1)
33+
expect(updateElementMock).toHaveBeenCalledWith(
3434
instance,
3535
{ test: false },
3636
{ test: true },
3737
)
3838

3939
rerender({ test: false })
40-
expect(updateElementMock).toBeCalledTimes(2)
41-
expect(updateElementMock).toBeCalledWith(
40+
expect(updateElementMock).toHaveBeenCalledTimes(2)
41+
expect(updateElementMock).toHaveBeenCalledWith(
4242
instance,
4343
{ test: false },
4444
{ test: false },

packages/core/__tests__/events.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { renderHook } from '@testing-library/react-hooks'
1+
import { renderHook } from '@testing-library/react'
22
import { Layer } from 'leaflet'
33

44
import { useEventHandlers } from '../src'

packages/core/__tests__/grid-layer.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ describe('grid-layer', () => {
99

1010
// No change when opacity is the same
1111
updateGridLayer(layer, { opacity }, { opacity })
12-
expect(layer.setOpacity).toBeCalledTimes(0)
12+
expect(layer.setOpacity).toHaveBeenCalledTimes(0)
1313

1414
// No change when opacity is nullish
1515
updateGridLayer(layer, { opacity: undefined }, { opacity })
16-
expect(layer.setOpacity).toBeCalledTimes(0)
16+
expect(layer.setOpacity).toHaveBeenCalledTimes(0)
1717

1818
updateGridLayer(layer, { opacity: 1 }, { opacity })
19-
expect(layer.setOpacity).toBeCalledTimes(1)
20-
expect(layer.setOpacity).toBeCalledWith(1)
19+
expect(layer.setOpacity).toHaveBeenCalledTimes(1)
20+
expect(layer.setOpacity).toHaveBeenCalledWith(1)
2121
})
2222

2323
test('updateGridLayer() updates the zIndex', () => {
@@ -28,14 +28,14 @@ describe('grid-layer', () => {
2828

2929
// No change when zIndex is the same
3030
updateGridLayer(layer, { zIndex }, { zIndex })
31-
expect(layer.setZIndex).toBeCalledTimes(0)
31+
expect(layer.setZIndex).toHaveBeenCalledTimes(0)
3232

3333
// No change when zIndex is nullish
3434
updateGridLayer(layer, { zIndex: null }, { zIndex })
35-
expect(layer.setZIndex).toBeCalledTimes(0)
35+
expect(layer.setZIndex).toHaveBeenCalledTimes(0)
3636

3737
updateGridLayer(layer, { zIndex: 20 }, { zIndex })
38-
expect(layer.setZIndex).toBeCalledTimes(1)
39-
expect(layer.setZIndex).toBeCalledWith(20)
38+
expect(layer.setZIndex).toHaveBeenCalledTimes(1)
39+
expect(layer.setZIndex).toHaveBeenCalledWith(20)
4040
})
4141
})

packages/core/__tests__/layer.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { renderHook } from '@testing-library/react-hooks'
1+
import { renderHook } from '@testing-library/react'
22

33
import { useLayerLifecycle } from '../src'
44

@@ -9,12 +9,12 @@ describe('layer', () => {
99

1010
const element = jest.fn()
1111
const { unmount } = renderHook(() => useLayerLifecycle(element, context))
12-
expect(map.addLayer).toBeCalledTimes(1)
13-
expect(map.addLayer).toBeCalledWith(element.instance)
12+
expect(map.addLayer).toHaveBeenCalledTimes(1)
13+
expect(map.addLayer).toHaveBeenCalledWith(element.instance)
1414

1515
unmount()
16-
expect(map.removeLayer).toBeCalledTimes(1)
17-
expect(map.removeLayer).toBeCalledWith(element.instance)
16+
expect(map.removeLayer).toHaveBeenCalledTimes(1)
17+
expect(map.removeLayer).toHaveBeenCalledWith(element.instance)
1818
})
1919

2020
test('useLayerLifecycle() adds the layer to the layerContainer when set and removes from the map', () => {
@@ -24,14 +24,14 @@ describe('layer', () => {
2424

2525
const element = { instance: jest.fn() }
2626
const { unmount } = renderHook(() => useLayerLifecycle(element, context))
27-
expect(layerContainer.addLayer).toBeCalledTimes(1)
28-
expect(layerContainer.addLayer).toBeCalledWith(element.instance)
27+
expect(layerContainer.addLayer).toHaveBeenCalledTimes(1)
28+
expect(layerContainer.addLayer).toHaveBeenCalledWith(element.instance)
2929

3030
unmount()
31-
expect(layerContainer.removeLayer).toBeCalledTimes(1)
31+
expect(layerContainer.removeLayer).toHaveBeenCalledTimes(1)
3232

33-
expect(map.addLayer).toBeCalledTimes(0)
34-
expect(map.removeLayer).toBeCalledTimes(1)
35-
expect(map.removeLayer).toBeCalledWith(element.instance)
33+
expect(map.addLayer).toHaveBeenCalledTimes(0)
34+
expect(map.removeLayer).toHaveBeenCalledTimes(1)
35+
expect(map.removeLayer).toHaveBeenCalledWith(element.instance)
3636
})
3737
})

packages/core/__tests__/media-overlay.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ describe('media-overlay', () => {
1111

1212
// No change when bounds are the same
1313
updateMediaOverlay(overlay, { bounds }, { bounds })
14-
expect(overlay.setBounds).toBeCalledTimes(0)
14+
expect(overlay.setBounds).toHaveBeenCalledTimes(0)
1515

1616
// No change when bounds are not an instance of LatLngBounds
1717
updateMediaOverlay(overlay, { bounds: [] }, { bounds })
18-
expect(overlay.setBounds).toBeCalledTimes(0)
18+
expect(overlay.setBounds).toHaveBeenCalledTimes(0)
1919

2020
const newBounds = latLngBounds([11, 11], [20, 20])
2121
updateMediaOverlay(overlay, { bounds: newBounds }, { bounds })
22-
expect(overlay.setBounds).toBeCalledTimes(1)
23-
expect(overlay.setBounds).toBeCalledWith(newBounds)
22+
expect(overlay.setBounds).toHaveBeenCalledTimes(1)
23+
expect(overlay.setBounds).toHaveBeenCalledWith(newBounds)
2424
})
2525

2626
test('updateMediaOverlay() updates the opacity', () => {
@@ -31,15 +31,15 @@ describe('media-overlay', () => {
3131

3232
// No change when opacity is the same
3333
updateMediaOverlay(overlay, { opacity }, { opacity })
34-
expect(overlay.setOpacity).toBeCalledTimes(0)
34+
expect(overlay.setOpacity).toHaveBeenCalledTimes(0)
3535

3636
// No change when opacity is nullish
3737
updateMediaOverlay(overlay, { opacity: undefined }, { opacity })
38-
expect(overlay.setOpacity).toBeCalledTimes(0)
38+
expect(overlay.setOpacity).toHaveBeenCalledTimes(0)
3939

4040
updateMediaOverlay(overlay, { opacity: 1 }, { opacity })
41-
expect(overlay.setOpacity).toBeCalledTimes(1)
42-
expect(overlay.setOpacity).toBeCalledWith(1)
41+
expect(overlay.setOpacity).toHaveBeenCalledTimes(1)
42+
expect(overlay.setOpacity).toHaveBeenCalledWith(1)
4343
})
4444

4545
test('updateMediaOverlay() updates the zIndex', () => {
@@ -50,14 +50,14 @@ describe('media-overlay', () => {
5050

5151
// No change when zIndex is the same
5252
updateMediaOverlay(overlay, { zIndex }, { zIndex })
53-
expect(overlay.setZIndex).toBeCalledTimes(0)
53+
expect(overlay.setZIndex).toHaveBeenCalledTimes(0)
5454

5555
// No change when zIndex is nullish
5656
updateMediaOverlay(overlay, { zIndex: null }, { zIndex })
57-
expect(overlay.setZIndex).toBeCalledTimes(0)
57+
expect(overlay.setZIndex).toHaveBeenCalledTimes(0)
5858

5959
updateMediaOverlay(overlay, { zIndex: 20 }, { zIndex })
60-
expect(overlay.setZIndex).toBeCalledTimes(1)
61-
expect(overlay.setZIndex).toBeCalledWith(20)
60+
expect(overlay.setZIndex).toHaveBeenCalledTimes(1)
61+
expect(overlay.setZIndex).toHaveBeenCalledWith(20)
6262
})
6363
})

packages/core/__tests__/path.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { renderHook } from '@testing-library/react-hooks'
1+
import { renderHook } from '@testing-library/react'
22

33
import { usePathOptions } from '../src'
44

@@ -11,18 +11,18 @@ describe('path', () => {
1111
const { rerender } = renderHook((p) => usePathOptions(element, p), {
1212
initialProps: { pathOptions: firstOptions },
1313
})
14-
expect(setStyle).toBeCalledTimes(1)
14+
expect(setStyle).toHaveBeenCalledTimes(1)
1515

1616
rerender({ pathOptions: firstOptions })
17-
expect(setStyle).toBeCalledTimes(1)
17+
expect(setStyle).toHaveBeenCalledTimes(1)
1818

1919
const secondOptions = { stroke: 2 }
2020
rerender({ pathOptions: secondOptions })
21-
expect(setStyle).toBeCalledTimes(2)
22-
expect(setStyle).toBeCalledWith(secondOptions)
21+
expect(setStyle).toHaveBeenCalledTimes(2)
22+
expect(setStyle).toHaveBeenCalledWith(secondOptions)
2323

2424
rerender({ pathOptions: null })
25-
expect(setStyle).toBeCalledTimes(3)
25+
expect(setStyle).toHaveBeenCalledTimes(3)
2626
expect(setStyle.mock.calls[2][0]).toEqual({})
2727
})
2828
})

packages/core/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
},
3636
"peerDependencies": {
3737
"leaflet": "^1.9.0",
38-
"react": "^18.0.0",
39-
"react-dom": "^18.0.0"
38+
"react": "beta",
39+
"react-dom": "beta"
4040
},
4141
"devDependencies": {
42-
"@types/react": "^18.0.28",
43-
"@types/react-dom": "^18.0.11"
42+
"@types/react": "npm:types-react@beta",
43+
"@types/react-dom": "npm:types-react-dom@beta"
4444
},
4545
"jest": {
4646
"extensionsToTreatAsEsm": [".ts", ".tsx"],

0 commit comments

Comments
 (0)