mirror of
https://github.com/google-map-react/google-map-react.git
synced 2025-12-08 18:26:32 +00:00
Add tests.
This commit is contained in:
parent
f0992ba668
commit
8accd13ea6
6
.travis.yml
Normal file
6
.travis.yml
Normal file
@ -0,0 +1,6 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "iojs-2"
|
||||
script:
|
||||
- npm run lint
|
||||
- npm test
|
||||
19
package.json
19
package.json
@ -7,10 +7,11 @@
|
||||
"build:lib": "babel ./src -d lib --ignore '__tests__'",
|
||||
"build:umd": "webpack src/index.js dist/GoogleMapReact.js --config webpack.config.dev.js",
|
||||
"build:umd:min": "webpack src/index.js dist/GoogleMapReact.min.js --config webpack.config.prod.js",
|
||||
"build": "npm run build:lib && npm run build:umd && npm run build:umd:min",
|
||||
"clean": "rimraf lib dist",
|
||||
"prepublish": "npm run clean && npm run build:lib && npm run build:umd && npm run build:umd:min",
|
||||
"eyetest": "babel-node ./src/__tests__/eye_test.js",
|
||||
"es5eyetest": "node ./lib/__tests__/eye_test.js"
|
||||
"prepublish": "npm run clean && npm run build",
|
||||
"lint": "eslint src",
|
||||
"test": "NODE_ENV=eee mocha --compilers js:babel/register --recursive"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -35,10 +36,6 @@
|
||||
},
|
||||
"homepage": "https://github.com/istarkov/google-map-react#readme",
|
||||
"dependencies": {
|
||||
"babel-eslint": "^4.1.3",
|
||||
"eslint": "^1.6.0",
|
||||
"eslint-config-airbnb": "^0.1.0",
|
||||
"eslint-plugin-react": "^3.5.1",
|
||||
"eventemitter3": "^1.1.0",
|
||||
"lodash.assign": "^3.2.0",
|
||||
"lodash.isfunction": "^3.0.5",
|
||||
@ -52,8 +49,16 @@
|
||||
"devDependencies": {
|
||||
"babel": "^5.8.23",
|
||||
"babel-core": "^5.8.25",
|
||||
"babel-eslint": "^4.1.3",
|
||||
"babel-loader": "^5.3.2",
|
||||
"eslint": "^1.6.0",
|
||||
"eslint-config-airbnb": "^0.1.0",
|
||||
"eslint-plugin-react": "^3.5.1",
|
||||
"expect": "^1.11.1",
|
||||
"jsdom": "^6.5.1",
|
||||
"mocha": "^2.3.3",
|
||||
"react": "^0.14.0-rc1",
|
||||
"react-addons-test-utils": "^0.14.0-rc1",
|
||||
"react-dom": "^0.14.0-rc1",
|
||||
"rimraf": "^2.4.3",
|
||||
"webpack": "^1.12.2"
|
||||
|
||||
@ -115,13 +115,12 @@ export default class GoogleMap extends Component {
|
||||
componentDidMount() {
|
||||
this.mounted_ = true;
|
||||
window.addEventListener('resize', this._onWindowResize);
|
||||
this.props.googleMapLoader(this.props.apiKey); // we can start load immediatly
|
||||
|
||||
setTimeout(() => { // to detect size
|
||||
this._setViewSize();
|
||||
if (this._isCenterDefined(this.props.center)) {
|
||||
this._initMap();
|
||||
} else {
|
||||
this.props.googleMapLoader(this.props.apiKey); // начать подгружать можно уже сейчас
|
||||
}
|
||||
}, 0, this);
|
||||
}
|
||||
|
||||
74
test/components/GoogleMap.spec.js
Normal file
74
test/components/GoogleMap.spec.js
Normal file
@ -0,0 +1,74 @@
|
||||
import './utils/jsdomInit.js';
|
||||
|
||||
const React = require('react');
|
||||
const { PropTypes, Component } = React;
|
||||
const expect = require('expect');
|
||||
|
||||
const TestUtils = require('react-addons-test-utils');
|
||||
const GoogleMap = require('../../src/index');
|
||||
|
||||
describe('Components', () => {
|
||||
it('Should work', () => {
|
||||
const mapMarkerClassName = 'mapMarkerClassName';
|
||||
|
||||
class MapMarker extends Component {
|
||||
render() {
|
||||
return (
|
||||
<div className={mapMarkerClassName}>Marker</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MapHolder extends Component { // eslint-disable-line react/no-multi-comp
|
||||
static propTypes = {
|
||||
center: PropTypes.array,
|
||||
zoom: PropTypes.number,
|
||||
greatPlaceCoords: PropTypes.any,
|
||||
};
|
||||
|
||||
static defaultProps = {
|
||||
center: [59.938043, 30.337157],
|
||||
zoom: 9,
|
||||
};
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<GoogleMap
|
||||
center={this.props.center}
|
||||
zoom={this.props.zoom}
|
||||
>
|
||||
<MapMarker lat={59.955413} lng={30.337844} />
|
||||
</GoogleMap>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const mapHolder = TestUtils.renderIntoDocument(
|
||||
<MapHolder />
|
||||
);
|
||||
|
||||
const marker = TestUtils.findRenderedDOMComponentWithClass(mapHolder, 'mapMarkerClassName');
|
||||
expect(marker.parentNode.style.left).toEqual('0.250129066669615px');
|
||||
expect(marker.parentNode.style.top).toEqual('-12.62811732746195px');
|
||||
});
|
||||
|
||||
it('Should call custom loader', () => {
|
||||
const API_KEY = 'API_KEY';
|
||||
const spy = expect.createSpy(() => {});
|
||||
const asyncSpy = async (a) => spy(a);
|
||||
|
||||
TestUtils.renderIntoDocument(
|
||||
<GoogleMap
|
||||
apiKey={API_KEY}
|
||||
googleMapLoader={asyncSpy}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(spy.calls.length).toEqual(1);
|
||||
expect(spy.calls[0].arguments[0]).toEqual(API_KEY);
|
||||
});
|
||||
});
|
||||
17
test/components/utils/jsdomInit.js
Normal file
17
test/components/utils/jsdomInit.js
Normal file
@ -0,0 +1,17 @@
|
||||
import jsdom from 'jsdom';
|
||||
|
||||
const doc = jsdom.jsdom('<!doctype html><html><body></body></html>');
|
||||
const win = doc.defaultView;
|
||||
global.document = doc;
|
||||
global.window = win;
|
||||
|
||||
function propagateToGlobal(window) {
|
||||
for (const key in window) {
|
||||
if (!window.hasOwnProperty(key)) continue;
|
||||
if (key in global) continue;
|
||||
|
||||
global[key] = window[key];
|
||||
}
|
||||
}
|
||||
|
||||
propagateToGlobal(win);
|
||||
Loading…
x
Reference in New Issue
Block a user