Skip to content

Commit ab7e852

Browse files
committed
test: add tests for getControl methods
1 parent 7bcd8d7 commit ab7e852

File tree

7 files changed

+29
-7
lines changed

7 files changed

+29
-7
lines changed

src/__mocks__/mapbox-gl.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ function GeolocateControl() {
137137
return this;
138138
}
139139

140+
GeolocateControl.prototype.on = function on(listener, fn) {
141+
fn({ target: this });
142+
};
143+
140144
function NavigationControl() {
141145
return this;
142146
}

src/components/AttributionControl/index.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ test('AttributionControl#render', () => {
1515
</MapGL>
1616
);
1717

18-
expect(wrapper.find('AttributionControl').exists()).toBe(true);
18+
const control = wrapper.find('AttributionControl');
19+
expect(control.exists()).toBe(true);
20+
expect(control.instance().getControl()).toBeTruthy();
1921

2022
wrapper.unmount();
2123
expect(wrapper.find('AttributionControl').exists()).toBe(false);

src/components/FullscreenControl/index.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ test('render', () => {
1111
</MapGL>
1212
);
1313

14-
expect(wrapper.find('FullscreenControl').exists()).toBe(true);
14+
const control = wrapper.find('FullscreenControl');
15+
expect(control.exists()).toBe(true);
16+
expect(control.instance().getControl()).toBeTruthy();
1517

1618
wrapper.unmount();
1719
expect(wrapper.find('FullscreenControl').exists()).toBe(false);

src/components/GeolocateControl/index.test.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@ import MapGL, { GeolocateControl } from '../..';
77
test('render', () => {
88
const wrapper = mount(
99
<MapGL latitude={0} longitude={0} zoom={0}>
10-
<GeolocateControl position="top-right" />
10+
<GeolocateControl
11+
position="top-right"
12+
onError={jest.fn()}
13+
onGeolocate={jest.fn()}
14+
onTrackUserLocationEnd={jest.fn()}
15+
onTrackUserLocationStart={jest.fn()}
16+
/>
1117
</MapGL>
1218
);
1319

14-
expect(wrapper.find('GeolocateControl').exists()).toBe(true);
20+
const control = wrapper.find('GeolocateControl');
21+
expect(control.exists()).toBe(true);
22+
expect(control.instance().getControl()).toBeTruthy();
1523

1624
wrapper.unmount();
1725
expect(wrapper.find('GeolocateControl').exists()).toBe(false);

src/components/LanguageControl/index.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ test('render', () => {
1111
</MapGL>
1212
);
1313

14-
expect(wrapper.find('LanguageControl').exists()).toBe(true);
14+
const control = wrapper.find('LanguageControl');
15+
expect(control.exists()).toBe(true);
16+
expect(control.instance().getControl()).toBeTruthy();
1517

1618
wrapper.unmount();
1719
expect(wrapper.find('LanguageControl').exists()).toBe(false);

src/components/NavigationControl/index.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ test('render', () => {
1111
</MapGL>
1212
);
1313

14-
expect(wrapper.find('NavigationControl').exists()).toBe(true);
14+
const control = wrapper.find('NavigationControl');
15+
expect(control.exists()).toBe(true);
16+
expect(control.instance().getControl()).toBeTruthy();
1517

1618
wrapper.unmount();
1719
expect(wrapper.find('NavigationControl').exists()).toBe(false);

src/components/ScaleControl/index.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ test('render', () => {
1111
</MapGL>
1212
);
1313

14-
expect(wrapper.find('ScaleControl').exists()).toBe(true);
14+
const control = wrapper.find('ScaleControl');
15+
expect(control.exists()).toBe(true);
16+
expect(control.instance().getControl()).toBeTruthy();
1517

1618
wrapper.unmount();
1719
expect(wrapper.find('ScaleControl').exists()).toBe(false);

0 commit comments

Comments
 (0)