Skip to content

Commit cf752a2

Browse files
committed
Tests passing again
1 parent 597faab commit cf752a2

File tree

5 files changed

+93
-56
lines changed

5 files changed

+93
-56
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
![](http://d.pr/i/C7qr.png)
44

5-
> A declarative Google Map React component using React, lazy-loading dependencies, and a test-driven approach by the [fullstack react](https://fullstackreact.com) team.
5+
> A declarative Google Map React component using React, lazy-loading dependencies, current-location finder and a test-driven approach by the [fullstack react](https://fullstackreact.com) team.
66
77
## Quickstart
88

@@ -28,6 +28,16 @@ Usage:
2828
</Map>
2929
```
3030

31+
## Map
32+
33+
The `<Map />` component _requires_ a `google` prop be included to work. Without the `google` prop, it will explode.
34+
35+
```javascript
36+
<Map google={window.google} />
37+
```
38+
39+
###
40+
3141
## Automatically Lazy-loading google api
3242

3343
The library includes a helper to wrap around the google maps API. The `GoogleApiWrapper` Higher-Order component accepts a configuration object which *must* include an `apiKey`. See [lib/GoogleApi.js](https://github.com/fullstackreact/google-maps-react/blob/master/src/lib/GoogleApi.js#L4) for all options it accepts.

scripts/mocha_runner.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,63 @@ global.navigator = {
2323

2424
chai.use(spies);
2525

26+
const google = {
27+
maps: {
28+
LatLng: function(lat, lng) {
29+
return {
30+
latitude: parseFloat(lat),
31+
longitude: parseFloat(lng),
32+
33+
lat: function() {
34+
return this.latitude;
35+
},
36+
lng: function() {
37+
return this.longitude;
38+
}
39+
};
40+
},
41+
LatLngBounds: function(ne, sw) {
42+
return {
43+
getSouthWest: function() {
44+
return sw;
45+
},
46+
getNorthEast: function() {
47+
return ne;
48+
}
49+
};
50+
},
51+
OverlayView: function() {
52+
return {};
53+
},
54+
InfoWindow: function() {
55+
return {};
56+
},
57+
Marker: function() {
58+
return {
59+
addListener: function() {}
60+
};
61+
},
62+
MarkerImage: function() {
63+
return {};
64+
},
65+
Map: function() {
66+
return {
67+
addListener: function() {},
68+
trigger: function() {}
69+
};
70+
},
71+
Point: function() {
72+
return {};
73+
},
74+
Size: function() {
75+
return {};
76+
},
77+
event: {
78+
trigger: function() {}
79+
}
80+
}
81+
};
82+
83+
global.google = google;
84+
2685
documentRef = document;

src/__tests__/components/Marker.spec.js

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Marker from '../../components/Marker';
1111
// google.maps.LatLng = function(lat, lng, opt_noWrap) {};
1212

1313
describe('Marker', () => {
14-
let map = null, google = null;
14+
let map = null, google = global.google;
1515
let sandbox;
1616
let LatLng = null;
1717
let location;
@@ -22,58 +22,6 @@ describe('Marker', () => {
2222
map = {}
2323
location = {lat: 37.759703, lng: -122.428093}
2424

25-
google = {
26-
maps: {
27-
LatLng: function(lat, lng) {
28-
return {
29-
latitude: parseFloat(lat),
30-
longitude: parseFloat(lng),
31-
32-
lat: function() {
33-
return this.latitude;
34-
},
35-
lng: function() {
36-
return this.longitude;
37-
}
38-
};
39-
},
40-
LatLngBounds: function(ne, sw) {
41-
return {
42-
getSouthWest: function() {
43-
return sw;
44-
},
45-
getNorthEast: function() {
46-
return ne;
47-
}
48-
};
49-
},
50-
OverlayView: function() {
51-
return {};
52-
},
53-
InfoWindow: function() {
54-
return {};
55-
},
56-
Marker: function() {
57-
return {
58-
addListener: function() {}
59-
};
60-
},
61-
MarkerImage: function() {
62-
return {};
63-
},
64-
Map: function() {
65-
return {};
66-
},
67-
Point: function() {
68-
return {};
69-
},
70-
Size: function() {
71-
return {};
72-
}
73-
}
74-
};
75-
76-
7725
sandbox.stub(google.maps, 'Map').returns(google.maps.Map);
7826
// sandbox.stub(google.maps, 'Marker').returns(google.maps.Marker);
7927
})

src/__tests__/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,23 @@ import React from 'react';
33
import {shallow, mount, render} from 'enzyme';
44
import {expect} from 'chai';
55
import sinon from 'sinon';
6+
7+
import Map from '../index';
8+
9+
describe('Map', () => {
10+
let wrapper;
11+
12+
describe('google prop', () => {
13+
it('explodes without a `google` prop', () => {
14+
expect(() => mount(<Map />)).to.throw(Error);
15+
});
16+
17+
it('does not explode with a `google` prop', () => {
18+
expect(() => mount(
19+
<Map
20+
google={global.google} />
21+
)).not.to.throw(Error);
22+
});
23+
});
24+
25+
})

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class Map extends React.Component {
2929
super(props)
3030

3131
invariant(!!props.google, 'You must include a `google` prop.');
32-
32+
3333
this.listeners = {}
3434
this.state = {
3535
currentLocation: {
@@ -179,7 +179,7 @@ export class Map extends React.Component {
179179
};
180180

181181
Map.propTypes = {
182-
google: T.object.isRequired,
182+
google: T.object,
183183
zoom: T.number,
184184
centerAroundCurrentLocation: T.bool,
185185
initialCenter: T.object,

0 commit comments

Comments
 (0)