Skip to content

Commit f92921e

Browse files
committed
Updated specs
1 parent 7c49229 commit f92921e

File tree

9 files changed

+128
-15
lines changed

9 files changed

+128
-15
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"babel-preset-react-hmre": "^1.1.1",
2929
"babel-preset-stage-2": "^6.5.0",
3030
"chai": "^3.5.0",
31+
"chai-spies": "^0.7.1",
3132
"css-loader": "^0.23.1",
3233
"dotenv": "^2.0.0",
3334
"enzyme": "^2.2.0",

scripts/mocha_runner.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ require('babel-core/register');
22
require('babel-polyfill');
33

44
var jsdom = require('jsdom').jsdom;
5+
var chai = require('chai'),
6+
spies = require('chai-spies');
7+
var sinon = require('sinon');
58

69
var exposedProperties = ['window', 'navigator', 'document'];
710

@@ -18,4 +21,6 @@ global.navigator = {
1821
userAgent: 'node.js'
1922
};
2023

24+
chai.use(spies);
25+
2126
documentRef = document;

src/__tests__/components/Marker.spec.js

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,103 @@ import {shallow, mount, render} from 'enzyme';
44
import {expect} from 'chai';
55
import sinon from 'sinon';
66

7-
import Marker from '../components/Marker';
7+
import Marker from '../../components/Marker';
8+
9+
// let google = {};
10+
// google.maps = {};
11+
// google.maps.LatLng = function(lat, lng, opt_noWrap) {};
12+
13+
describe('Marker', () => {
14+
let map = null, google = null;
15+
let sandbox;
16+
let LatLng = null;
17+
let location;
18+
19+
beforeEach(() => {
20+
sandbox = sinon.sandbox.create();
21+
22+
map = {}
23+
location = {lat: 37.759703, lng: -122.428093}
24+
25+
google = {
26+
maps: {
27+
LatLng: function(lat, lng) {
28+
return {
29+
latitude: parseFloat(lat),
30+
longitude: parseFloat(lng),
31+
32+
lat: function() { return this.latitude; },
33+
lng: function() { return this.longitude; }
34+
};
35+
},
36+
LatLngBounds: function(ne, sw) {
37+
return {
38+
getSouthWest: function() { return sw; },
39+
getNorthEast: function() { return ne; }
40+
};
41+
},
42+
OverlayView: function() {
43+
return {};
44+
},
45+
InfoWindow: function() {
46+
return {};
47+
},
48+
Marker: function() {
49+
return {
50+
addListener: function() {}
51+
};
52+
},
53+
MarkerImage: function() {
54+
return {};
55+
},
56+
Map: function() {
57+
return {};
58+
},
59+
Point: function() {
60+
return {};
61+
},
62+
Size: function() {
63+
return {};
64+
}
65+
}
66+
};
67+
68+
69+
sandbox.stub(google.maps, 'Map').returns(google.maps.Map);
70+
// sandbox.stub(google.maps, 'Marker').returns(google.maps.Marker);
71+
})
72+
73+
afterEach(() => {
74+
sandbox.restore();
75+
})
76+
77+
it('accepts a `map` and a `google` prop', () => {
78+
const wrapper = mount(<Marker google={google} map={map} />);
79+
expect(wrapper.props().google).to.equal(google);
80+
expect(wrapper.props().map).to.equal(map);
81+
});
82+
83+
describe('LatLng', () => {
84+
let wrapper;
85+
beforeEach(() => {
86+
sandbox.stub(google.maps, 'LatLng')
87+
.returns(sinon.createStubInstance(google.maps.LatLng));
88+
sandbox.spy(google.maps, 'Marker')
89+
wrapper = mount(<Marker google={google}
90+
position={location} />);
91+
});
92+
93+
it('creates a location from the position prop', () => {
94+
wrapper.setProps({map: map})
95+
sinon.assert
96+
.calledWith(google.maps.LatLng, location.lat, location.lng)
97+
});
98+
99+
it('creates a Marker from the position prop', () => {
100+
wrapper.setProps({map: map})
101+
sinon.assert.called(google.maps.Marker)
102+
});
103+
104+
})
105+
106+
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {shallow, mount, render} from 'enzyme';
44
import {expect} from 'chai';
55
import sinon from 'sinon';
66

7-
import GoogleApi from '../lib/GoogleApi'
7+
import GoogleApi from '../../lib/GoogleApi'
88

99
const base = 'https://maps.googleapis.com/maps/api/js'
1010

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from 'chai';
1111

1212
const createCache = (obj, newElement) => {
13-
const ScriptCache = require('../lib/ScriptCache').ScriptCache;
13+
const ScriptCache = require('../../lib/ScriptCache').ScriptCache;
1414
let cache = ScriptCache(obj);
1515
cache._scriptTag = sinon.spy(cache, '_scriptTag')
1616
return cache;

src/__tests__/lib/String.spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react';
2+
3+
import {expect} from 'chai';
4+
import sinon from 'sinon';
5+
6+
import { camelize } from '../../lib/String'
7+
8+
describe('string', () => {
9+
it('camelizes words', () => {
10+
expect(camelize('hello world')).to.equal('HelloWorld');
11+
expect(camelize('mousemove')).to.equal('Mousemove');
12+
})
13+
})

src/components/Marker.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import React, { PropTypes as T } from 'react'
22

3-
const camelize = function(str) {
4-
return str.split(' ').map(function(word){
5-
return word.charAt(0).toUpperCase() + word.slice(1);
6-
}).join('');
7-
}
8-
3+
import { camelize } from '../lib/String'
94
const evtNames = ['click', 'mouseover'];
105

116
export class Marker extends React.Component {

src/index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, {PropTypes as T} from 'react';
22
import ReactDOM from 'react-dom'
3+
import { camelize } from './lib/String'
34

45
const mapStyles = {
56
map: {
@@ -10,12 +11,6 @@ const mapStyles = {
1011
}
1112
}
1213

13-
const camelize = function(str) {
14-
return str.split(' ').map(function(word){
15-
return word.charAt(0).toUpperCase() + word.slice(1);
16-
}).join('');
17-
}
18-
1914
const evtNames = ['click', 'dragend'];
2015

2116
class Map extends React.Component {

src/lib/String.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const camelize = function(str) {
2+
return str.split(' ').map(function(word) {
3+
return word.charAt(0).toUpperCase() + word.slice(1);
4+
}).join('');
5+
}

0 commit comments

Comments
 (0)