Skip to content

Commit

Permalink
test: add tests for getControl methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stepankuzmin committed Apr 8, 2019
1 parent 7bcd8d7 commit ab7e852
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/__mocks__/mapbox-gl.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ function GeolocateControl() {
return this;
}

GeolocateControl.prototype.on = function on(listener, fn) {
fn({ target: this });
};

function NavigationControl() {
return this;
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/AttributionControl/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ test('AttributionControl#render', () => {
</MapGL>
);

expect(wrapper.find('AttributionControl').exists()).toBe(true);
const control = wrapper.find('AttributionControl');
expect(control.exists()).toBe(true);
expect(control.instance().getControl()).toBeTruthy();

wrapper.unmount();
expect(wrapper.find('AttributionControl').exists()).toBe(false);
Expand Down
4 changes: 3 additions & 1 deletion src/components/FullscreenControl/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ test('render', () => {
</MapGL>
);

expect(wrapper.find('FullscreenControl').exists()).toBe(true);
const control = wrapper.find('FullscreenControl');
expect(control.exists()).toBe(true);
expect(control.instance().getControl()).toBeTruthy();

wrapper.unmount();
expect(wrapper.find('FullscreenControl').exists()).toBe(false);
Expand Down
12 changes: 10 additions & 2 deletions src/components/GeolocateControl/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ import MapGL, { GeolocateControl } from '../..';
test('render', () => {
const wrapper = mount(
<MapGL latitude={0} longitude={0} zoom={0}>
<GeolocateControl position="top-right" />
<GeolocateControl
position="top-right"
onError={jest.fn()}
onGeolocate={jest.fn()}
onTrackUserLocationEnd={jest.fn()}
onTrackUserLocationStart={jest.fn()}
/>
</MapGL>
);

expect(wrapper.find('GeolocateControl').exists()).toBe(true);
const control = wrapper.find('GeolocateControl');
expect(control.exists()).toBe(true);
expect(control.instance().getControl()).toBeTruthy();

wrapper.unmount();
expect(wrapper.find('GeolocateControl').exists()).toBe(false);
Expand Down
4 changes: 3 additions & 1 deletion src/components/LanguageControl/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ test('render', () => {
</MapGL>
);

expect(wrapper.find('LanguageControl').exists()).toBe(true);
const control = wrapper.find('LanguageControl');
expect(control.exists()).toBe(true);
expect(control.instance().getControl()).toBeTruthy();

wrapper.unmount();
expect(wrapper.find('LanguageControl').exists()).toBe(false);
Expand Down
4 changes: 3 additions & 1 deletion src/components/NavigationControl/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ test('render', () => {
</MapGL>
);

expect(wrapper.find('NavigationControl').exists()).toBe(true);
const control = wrapper.find('NavigationControl');
expect(control.exists()).toBe(true);
expect(control.instance().getControl()).toBeTruthy();

wrapper.unmount();
expect(wrapper.find('NavigationControl').exists()).toBe(false);
Expand Down
4 changes: 3 additions & 1 deletion src/components/ScaleControl/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ test('render', () => {
</MapGL>
);

expect(wrapper.find('ScaleControl').exists()).toBe(true);
const control = wrapper.find('ScaleControl');
expect(control.exists()).toBe(true);
expect(control.instance().getControl()).toBeTruthy();

wrapper.unmount();
expect(wrapper.find('ScaleControl').exists()).toBe(false);
Expand Down

0 comments on commit ab7e852

Please sign in to comment.