Skip to content

Commit 021126f

Browse files
committed
Fix tests for setCenter which is now async
1 parent b0de956 commit 021126f

File tree

1 file changed

+30
-17
lines changed

1 file changed

+30
-17
lines changed

client/src/tests/MapboxManager.test.js

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,24 @@ describe('Test mapboxManager', () => {
1010
const mapboxManagerWithoutMap = new MapboxManager();
1111
const coords = [37.75034979203168, -122.41554467258297];
1212

13-
it('calls mapboxManager setCenter happy path', () => {
14-
mapboxManager.setCenter({ coords, regionType: REGION_TYPES.PLACE });
13+
afterEach(() => {
14+
mapboxManagerWithoutMap.setMap(null);
15+
});
16+
17+
it('calls mapboxManager setCenter happy path', async () => {
18+
await mapboxManager.setCenter({ coords, regionType: REGION_TYPES.PLACE });
1519
expect(mapMock.flyTo).toBeCalledWith({
1620
center: coords,
1721
zoom: 12,
1822
});
19-
mapboxManager.setCenter({ coords, regionType: REGION_TYPES.LATLONG });
23+
24+
await mapboxManager.setCenter({ coords, regionType: REGION_TYPES.LATLONG });
2025
expect(mapMock.flyTo).toBeCalledWith({
2126
center: coords,
2227
zoom: 17,
2328
});
2429

25-
mapboxManager.setCenter({
30+
await mapboxManager.setCenter({
2631
coords,
2732
regionType: [REGION_TYPES.LATLONG, REGION_TYPES.LOCALITY],
2833
});
@@ -31,42 +36,50 @@ describe('Test mapboxManager', () => {
3136
zoom: 17,
3237
});
3338

34-
mapboxManagerWithoutMap.setCenter({
39+
const setCenterPromise = mapboxManagerWithoutMap.setCenter({
3540
coords,
3641
regionType: REGION_TYPES.COUNTRY,
3742
});
3843
mapboxManagerWithoutMap.setMap(mapMock);
44+
await setCenterPromise;
3945
expect(mapMock.flyTo).toBeCalledWith({
4046
center: coords,
4147
zoom: 4.5,
4248
});
43-
mapboxManagerWithoutMap.setMap(null);
4449
});
4550

4651
// Unknown region types all default to same result as not passing region type at all
47-
it('calls mapboxManager setCenter with unknown region type', () => {
48-
mapboxManager.setCenter({ coords });
52+
it('calls mapboxManager setCenter with unknown region type', async () => {
53+
await mapboxManager.setCenter({ coords });
4954
expect(mapMock.flyTo).toBeCalledWith({
5055
center: coords,
5156
});
5257

53-
mapboxManager.setCenter({ coords, regionType: REGION_TYPES.CITY });
58+
await mapboxManager.setCenter({ coords, regionType: REGION_TYPES.CITY });
5459
expect(mapMock.flyTo).toBeCalledWith({
5560
center: coords,
5661
});
5762
});
5863

5964
// More test cases should eventually fall into this category
60-
it('calls mapboxManager setCenter and throws error', () => {
61-
expect(() => mapboxManager.setCenter()).toThrowError(TypeError);
65+
it('calls mapboxManager setCenter and throws error', async () => {
66+
try {
67+
await mapboxManager.setCenter();
68+
} catch (e) {
69+
expect(e).toBeInstanceOf(TypeError);
70+
}
6271

63-
expect(() =>
64-
mapboxManager.setCenter(coords, REGION_TYPES.PLACE),
65-
).toThrowError(Error);
72+
try {
73+
await mapboxManager.setCenter(coords, REGION_TYPES.PLACE);
74+
} catch (e) {
75+
expect(e).toBeInstanceOf(Error);
76+
}
6677

67-
expect(() =>
68-
mapboxManager.setCenter({ regionType: REGION_TYPES.PLACE }),
69-
).toThrowError(Error);
78+
try {
79+
await mapboxManager.setCenter({ regionType: REGION_TYPES.PLACE });
80+
} catch (e) {
81+
expect(e).toBeInstanceOf(Error);
82+
}
7083
});
7184

7285
it('calls mapboxManager getCenter happy path', () => {

0 commit comments

Comments
 (0)