1
- import { shallow , ShallowWrapper } from "enzyme" ;
1
+ import "@testing-library/jest-dom" ;
2
+ import { render , RenderResult } from "@testing-library/react" ;
2
3
import { createElement } from "react" ;
3
4
import { LeafletMap , LeafletProps } from "../LeafletMap" ;
4
5
@@ -23,79 +24,47 @@ describe("Leaflet maps", () => {
23
24
zoomLevel : 10
24
25
} ;
25
26
26
- const renderLeafletMap = ( props : LeafletProps ) : ShallowWrapper < LeafletProps , any > =>
27
- shallow ( createElement ( LeafletMap , props ) ) ;
27
+ function renderLeafletMap ( props : Partial < LeafletProps > = { } ) : RenderResult {
28
+ return render ( < LeafletMap { ...defaultProps } { ...props } /> ) ;
29
+ }
28
30
29
31
it ( "renders a map with right structure" , ( ) => {
30
- const leafletMaps = renderLeafletMap ( defaultProps ) ;
31
- leafletMaps . setProps ( {
32
- heightUnit : "percentageOfWidth" ,
33
- widthUnit : "pixels"
34
- } ) ;
35
-
36
- expect ( leafletMaps ) . toMatchSnapshot ( ) ;
32
+ const { asFragment } = renderLeafletMap ( { heightUnit : "percentageOfWidth" , widthUnit : "pixels" } ) ;
33
+ expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
37
34
} ) ;
38
35
39
36
it ( "renders a map with pixels renders structure correctly" , ( ) => {
40
- const leafletMaps = renderLeafletMap ( defaultProps ) ;
41
- leafletMaps . setProps ( {
42
- heightUnit : "pixels" ,
43
- widthUnit : "pixels"
44
- } ) ;
45
-
46
- expect ( leafletMaps ) . toMatchSnapshot ( ) ;
37
+ const { asFragment } = renderLeafletMap ( { heightUnit : "pixels" , widthUnit : "pixels" } ) ;
38
+ expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
47
39
} ) ;
48
40
49
41
it ( "renders a map with percentage of width and height units renders the structure correctly" , ( ) => {
50
- const leafletMaps = renderLeafletMap ( defaultProps ) ;
51
- leafletMaps . setProps ( {
52
- heightUnit : "percentageOfWidth" ,
53
- widthUnit : "percentage"
54
- } ) ;
55
-
56
- expect ( leafletMaps ) . toMatchSnapshot ( ) ;
42
+ const { asFragment } = renderLeafletMap ( { heightUnit : "percentageOfWidth" , widthUnit : "percentage" } ) ;
43
+ expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
57
44
} ) ;
58
45
59
46
it ( "renders a map with percentage of parent units renders the structure correctly" , ( ) => {
60
- const leafletMaps = renderLeafletMap ( defaultProps ) ;
61
- leafletMaps . setProps ( {
62
- heightUnit : "percentageOfParent" ,
63
- widthUnit : "percentage"
64
- } ) ;
65
-
66
- expect ( leafletMaps ) . toMatchSnapshot ( ) ;
47
+ const { asFragment } = renderLeafletMap ( { heightUnit : "percentageOfParent" , widthUnit : "percentage" } ) ;
48
+ expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
67
49
} ) ;
68
50
69
51
it ( "renders a map with HERE maps as provider" , ( ) => {
70
- const leafletMaps = renderLeafletMap ( defaultProps ) ;
71
- leafletMaps . setProps ( {
72
- mapProvider : "hereMaps"
73
- } ) ;
74
-
75
- expect ( leafletMaps ) . toMatchSnapshot ( ) ;
52
+ const { asFragment } = renderLeafletMap ( { mapProvider : "hereMaps" } ) ;
53
+ expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
76
54
} ) ;
77
55
78
56
it ( "renders a map with MapBox maps as provider" , ( ) => {
79
- const leafletMaps = renderLeafletMap ( defaultProps ) ;
80
- leafletMaps . setProps ( {
81
- mapProvider : "mapBox"
82
- } ) ;
83
-
84
- expect ( leafletMaps ) . toMatchSnapshot ( ) ;
57
+ const { asFragment } = renderLeafletMap ( { mapProvider : "mapBox" } ) ;
58
+ expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
85
59
} ) ;
86
60
87
61
it ( "renders a map with attribution" , ( ) => {
88
- const leafletMaps = renderLeafletMap ( defaultProps ) ;
89
- leafletMaps . setProps ( {
90
- attributionControl : true
91
- } ) ;
92
-
93
- expect ( leafletMaps ) . toMatchSnapshot ( ) ;
62
+ const { asFragment } = renderLeafletMap ( { attributionControl : true } ) ;
63
+ expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
94
64
} ) ;
95
65
96
66
it ( "renders a map with markers" , ( ) => {
97
- const leafletMaps = renderLeafletMap ( defaultProps ) ;
98
- leafletMaps . setProps ( {
67
+ const { asFragment } = renderLeafletMap ( {
99
68
locations : [
100
69
{
101
70
title : "Mendix HQ" ,
@@ -111,21 +80,18 @@ describe("Leaflet maps", () => {
111
80
}
112
81
]
113
82
} ) ;
114
-
115
- expect ( leafletMaps ) . toMatchSnapshot ( ) ;
83
+ expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
116
84
} ) ;
117
85
118
86
it ( "renders a map with current location" , ( ) => {
119
- const leafletMaps = renderLeafletMap ( defaultProps ) ;
120
- leafletMaps . setProps ( {
87
+ const { asFragment } = renderLeafletMap ( {
121
88
showCurrentLocation : true ,
122
89
currentLocation : {
123
90
latitude : 51.906688 ,
124
91
longitude : 4.48837 ,
125
92
url : "image:url"
126
93
}
127
94
} ) ;
128
-
129
- expect ( leafletMaps ) . toMatchSnapshot ( ) ;
95
+ expect ( asFragment ( ) ) . toMatchSnapshot ( ) ;
130
96
} ) ;
131
97
} ) ;
0 commit comments