diff --git a/__tests__/LayersControl.js b/__tests__/LayersControl.js index cb4f9570..8d5e820d 100644 --- a/__tests__/LayersControl.js +++ b/__tests__/LayersControl.js @@ -1,18 +1,11 @@ -/* global describe, expect, it, jest */ +/* global describe, expect, it */ -import Leaflet from 'leaflet'; -import React, { Component } from 'react'; -import { renderIntoDocument } from 'react-addons-test-utils'; +import Leaflet from 'leaflet' +import React, { Component } from 'react' +import { renderIntoDocument } from 'react-addons-test-utils' -import LayersControl from '../src/LayersControl'; -import Map from '../src/Map'; - -jest.unmock('../src/LayersControl'); -jest.unmock('../src/Map'); -jest.unmock('../src/MapComponent'); -jest.unmock('../src/types/bounds'); -jest.unmock('../src/types/index'); -jest.unmock('../src/types/latlng'); +import LayersControl from '../src/LayersControl' +import Map from '../src/Map' describe('LayersControl', () => { it('passes its `map` context to its children', () => { @@ -21,12 +14,12 @@ describe('LayersControl', () => { map: React.PropTypes.instanceOf(Leaflet.Map), }; - componentWillMount() { - expect(this.context.map).toBeDefined(); + componentWillMount () { + expect(this.context.map).toBeDefined() } - render() { - return null; + render () { + return null } } @@ -38,6 +31,6 @@ describe('LayersControl', () => { - ); - }); -}); + ) + }) +}) diff --git a/__tests__/Map.js b/__tests__/Map.js index 6c7ec3e1..2e0139d4 100644 --- a/__tests__/Map.js +++ b/__tests__/Map.js @@ -1,114 +1,108 @@ -/* global describe, expect, it, jest */ +/* global describe, expect, it */ -import React, { Component } from 'react'; -import { renderIntoDocument } from 'react-addons-test-utils'; -import { renderToStaticMarkup } from 'react-dom/server'; +import React, { Component } from 'react' +import { renderIntoDocument } from 'react-addons-test-utils' +import { renderToStaticMarkup } from 'react-dom/server' -import Map from '../src/Map'; - -jest.unmock('../src/Map'); -jest.unmock('../src/MapComponent'); -jest.unmock('../src/types/bounds'); -jest.unmock('../src/types/index'); -jest.unmock('../src/types/latlng'); +import Map from '../src/Map' describe('Map', () => { it('only renders the container div server-side', () => { class TestComponent extends Component { - render() { - return test; + render () { + return test } } - const component = ; - const html = renderToStaticMarkup(component); + const component = + const html = renderToStaticMarkup(component) - expect(html).toBe('
'); - }); + expect(html).toBe('
') + }) it('sets center and zoom props', () => { - const center = [1.2, 3.4]; - const zoom = 10; + const center = [1.2, 3.4] + const zoom = 10 - const map = renderIntoDocument(); - const mapLeaflet = map.leafletElement; + const map = renderIntoDocument() + const mapLeaflet = map.leafletElement - expect(mapLeaflet.getCenter().lat).toBe(center[0]); - expect(mapLeaflet.getCenter().lng).toBe(center[1]); - expect(mapLeaflet.getZoom()).toBe(zoom); - }); + expect(mapLeaflet.getCenter().lat).toBe(center[0]) + expect(mapLeaflet.getCenter().lng).toBe(center[1]) + expect(mapLeaflet.getZoom()).toBe(zoom) + }) it('sets bounds', () => { - const bounds = [[0, 0], [2, 2]]; + const bounds = [[0, 0], [2, 2]] const map = renderIntoDocument() - const mapBounds = map.leafletElement.getBounds(); - expect(mapBounds).toBe(bounds); - }); + const mapBounds = map.leafletElement.getBounds() + expect(mapBounds).toBe(bounds) + }) it('updates center and zoom props', () => { class TestComponent extends Component { - constructor() { - super(); + constructor () { + super() this.state = { center: [1.2, 3.4], zoom: 10, - }; + } } - getLeafletMap() { - return this.refs.map.leafletElement; + getLeafletMap () { + return this.refs.map.leafletElement } - updatePosition() { + updatePosition () { this.setState({ center: [2.3, 4.5], zoom: 12, - }); + }) } - render() { - return ; + render () { + return } } - const component = renderIntoDocument(); - const mapLeaflet = component.getLeafletMap(); + const component = renderIntoDocument() + const mapLeaflet = component.getLeafletMap() - expect(mapLeaflet.getCenter().lat).toBe(1.2); - expect(mapLeaflet.getCenter().lng).toBe(3.4); - expect(mapLeaflet.getZoom()).toBe(10); + expect(mapLeaflet.getCenter().lat).toBe(1.2) + expect(mapLeaflet.getCenter().lng).toBe(3.4) + expect(mapLeaflet.getZoom()).toBe(10) - component.updatePosition(); - expect(mapLeaflet.getCenter().lat).toBe(2.3); - expect(mapLeaflet.getCenter().lng).toBe(4.5); - expect(mapLeaflet.getZoom()).toBe(12); - }); + component.updatePosition() + expect(mapLeaflet.getCenter().lat).toBe(2.3) + expect(mapLeaflet.getCenter().lng).toBe(4.5) + expect(mapLeaflet.getZoom()).toBe(12) + }) it('updates bounds props', () => { - const firstBounds = [[0, 0], [2, 2]]; + const firstBounds = [[0, 0], [2, 2]] const secondBounds = [[0, 0], [-2, -2]] class TestComponent extends Component { - constructor() { - super(); + constructor () { + super() this.state = { bounds: firstBounds, - }; + } } - getLeafletMap() { - return this.refs.map.leafletElement; + getLeafletMap () { + return this.refs.map.leafletElement } - updatePosition() { + updatePosition () { this.setState({ bounds: secondBounds, - }); + }) } - render() { - return ; + render () { + return } } - const component = renderIntoDocument(); - const mapLeaflet = component.getLeafletMap(); + const component = renderIntoDocument() + const mapLeaflet = component.getLeafletMap() - expect(mapLeaflet.getBounds()).toBe(firstBounds); - component.updatePosition(); - expect(mapLeaflet.getBounds()).toBe(secondBounds); - }); -}); + expect(mapLeaflet.getBounds()).toBe(firstBounds) + component.updatePosition() + expect(mapLeaflet.getBounds()).toBe(secondBounds) + }) +}) diff --git a/__tests__/MapComponent.js b/__tests__/MapComponent.js index d220b711..c809b4ff 100644 --- a/__tests__/MapComponent.js +++ b/__tests__/MapComponent.js @@ -1,102 +1,100 @@ /* global describe, expect, it, jest */ -import Leaflet from 'leaflet'; -import React, { Component } from 'react'; -import { renderIntoDocument } from 'react-addons-test-utils'; +import Leaflet from 'leaflet' +import React, { Component } from 'react' +import { renderIntoDocument } from 'react-addons-test-utils' -import MapComponent from '../src/MapComponent'; - -jest.unmock('../src/MapComponent'); +import MapComponent from '../src/MapComponent' describe('MapComponent', () => { class TestComponent extends MapComponent { - componentWillMount() { - super.componentWillMount(); - this.leafletElement = Leaflet.map('test'); + componentWillMount () { + super.componentWillMount() + this.leafletElement = Leaflet.map('test') } - render() { - return null; + render () { + return null } } it('exposes a `leafletElement` getter', () => { - const component = renderIntoDocument(); - expect(component.leafletElement._container).toBeDefined(); - }); + const component = renderIntoDocument() + expect(component.leafletElement._container).toBeDefined() + }) it('binds the event', () => { - const callback = jest.genMockFn(); - const component = renderIntoDocument(); - component.fireLeafletEvent('click'); - expect(callback.mock.calls.length).toBe(1); - }); + const callback = jest.fn() + const component = renderIntoDocument() + component.fireLeafletEvent('click') + expect(callback.mock.calls.length).toBe(1) + }) it('unbinds the event', () => { - const callback = jest.genMockFn(); + const callback = jest.fn() class EventComponent extends Component { - constructor() { - super(); - this.state = {bindEvent: true}; + constructor () { + super() + this.state = {bindEvent: true} } - dontBind() { - this.setState({bindEvent: false}); + dontBind () { + this.setState({bindEvent: false}) } - fire() { - this.refs.c.fireLeafletEvent('click'); + fire () { + this.refs.c.fireLeafletEvent('click') } - render() { + render () { return this.state.bindEvent ? - : ; + : } } - const component = renderIntoDocument(); + const component = renderIntoDocument() - component.fire(); - expect(callback.mock.calls.length).toBe(1); + component.fire() + expect(callback.mock.calls.length).toBe(1) - component.dontBind(); - component.fire(); - expect(callback.mock.calls.length).toBe(1); - }); + component.dontBind() + component.fire() + expect(callback.mock.calls.length).toBe(1) + }) it('replaces the event', () => { - const callback1 = jest.genMockFn(); - const callback2 = jest.genMockFn(); + const callback1 = jest.fn() + const callback2 = jest.fn() class EventComponent extends Component { - constructor() { - super(); - this.state = {cb: callback1}; + constructor () { + super() + this.state = {cb: callback1} } - replaceCallback() { - this.setState({cb: callback2}); + replaceCallback () { + this.setState({cb: callback2}) } - fire() { - this.refs.c.fireLeafletEvent('click'); + fire () { + this.refs.c.fireLeafletEvent('click') } - render() { - return ; + render () { + return } } - const component = renderIntoDocument(); + const component = renderIntoDocument() - component.fire(); - expect(callback1.mock.calls.length).toBe(1); - expect(callback2.mock.calls.length).toBe(0); + component.fire() + expect(callback1.mock.calls.length).toBe(1) + expect(callback2.mock.calls.length).toBe(0) - component.replaceCallback(); - component.fire(); - expect(callback1.mock.calls.length).toBe(1); - expect(callback2.mock.calls.length).toBe(1); - }); -}); + component.replaceCallback() + component.fire() + expect(callback1.mock.calls.length).toBe(1) + expect(callback2.mock.calls.length).toBe(1) + }) +}) diff --git a/__tests__/MapLayer.js b/__tests__/MapLayer.js index d80d34ce..0227e806 100644 --- a/__tests__/MapLayer.js +++ b/__tests__/MapLayer.js @@ -1,18 +1,11 @@ -/* global describe, expect, it, jest */ +/* global describe, expect, it */ -import Leaflet from 'leaflet'; -import React, { Component } from 'react'; -import { renderIntoDocument } from 'react-addons-test-utils'; +import Leaflet from 'leaflet' +import React, { Component } from 'react' +import { renderIntoDocument } from 'react-addons-test-utils' -import Map from '../src/Map'; -import MapLayer from '../src/MapLayer'; - -jest.unmock('../src/MapComponent'); -jest.unmock('../src/MapLayer'); -jest.unmock('../src/Map'); -jest.unmock('../src/types/bounds'); -jest.unmock('../src/types/index'); -jest.unmock('../src/types/latlng'); +import Map from '../src/Map' +import MapLayer from '../src/MapLayer' describe('MapLayer', () => { it('passes its `map` context to its children', () => { @@ -21,14 +14,14 @@ describe('MapLayer', () => { map: React.PropTypes.instanceOf(Leaflet.Map), }; - componentWillMount() { - super.componentWillMount(); - expect(this.context.map).toBeDefined(); - this.leafletElement = Leaflet.marker([0, 0]); + componentWillMount () { + super.componentWillMount() + expect(this.context.map).toBeDefined() + this.leafletElement = Leaflet.marker([0, 0]) } - render() { - return
{this.props.children}
; + render () { + return
{this.props.children}
} } @@ -37,12 +30,12 @@ describe('MapLayer', () => { map: React.PropTypes.instanceOf(Leaflet.Map), }; - componentWillMount() { - expect(this.context.map).toBeDefined(); + componentWillMount () { + expect(this.context.map).toBeDefined() } - render() { - return null; + render () { + return null } } @@ -52,6 +45,6 @@ describe('MapLayer', () => {
- ); - }); -}); + ) + }) +}) diff --git a/__tests__/Marker.js b/__tests__/Marker.js index 2257f0f8..d1a7861d 100644 --- a/__tests__/Marker.js +++ b/__tests__/Marker.js @@ -1,36 +1,23 @@ /* global describe, expect, it, jest */ -import Leaflet from 'leaflet'; -import React from 'react'; -import { renderIntoDocument } from 'react-addons-test-utils'; +import Leaflet from 'leaflet' +import React from 'react' +import { renderIntoDocument } from 'react-addons-test-utils' -import { Map, Marker, TileLayer } from '../src/'; - -jest.unmock('../src/BaseTileLayer'); -jest.unmock('../src/index'); -jest.unmock('../src/Map'); -jest.unmock('../src/MapComponent'); -jest.unmock('../src/MapControl'); -jest.unmock('../src/MapLayer'); -jest.unmock('../src/Marker'); -jest.unmock('../src/Path'); -jest.unmock('../src/TileLayer'); -jest.unmock('../src/types/bounds'); -jest.unmock('../src/types/index'); -jest.unmock('../src/types/latlng'); +import { Map, Marker, TileLayer } from '../src/' describe('Marker', () => { it('adds the marker to the map', () => { - Leaflet.marker = jest.genMockFunction(); - const position = [0, 0]; + Leaflet.marker = jest.fn() + const position = [0, 0] renderIntoDocument( - ); + ) - expect(Leaflet.marker.mock.calls[0][0]).toBe(position); - }); -}); + expect(Leaflet.marker.mock.calls[0][0]).toBe(position) + }) +}) diff --git a/__tests__/Popup.js b/__tests__/Popup.js index f15ac628..8bc01686 100644 --- a/__tests__/Popup.js +++ b/__tests__/Popup.js @@ -1,95 +1,80 @@ /* global describe, expect, it, jest */ /* eslint-disable react/no-did-mount-set-state, react/no-did-update-set-state */ -import Leaflet from 'leaflet'; -import React, { Component } from 'react'; -import { renderIntoDocument } from 'react-addons-test-utils'; +import Leaflet from 'leaflet' +import React, { Component } from 'react' +import { renderIntoDocument } from 'react-addons-test-utils' -import { Map, Popup, TileLayer } from '../src/'; - -jest.unmock('../src/BaseTileLayer'); -jest.unmock('../src/MapComponent'); -jest.unmock('../src/MapControl'); -jest.unmock('../src/MapLayer'); -jest.unmock('../src/Map'); -jest.unmock('../src/Marker'); -jest.unmock('../src/Popup'); -jest.unmock('../src/TileLayer'); -jest.unmock('../src/index'); -jest.unmock('../src/Path'); -jest.unmock('../src/types/bounds'); -jest.unmock('../src/types/index'); -jest.unmock('../src/types/latlng'); +import { Map, Popup, TileLayer } from '../src/' describe('Popup', () => { it('adds the popup to the map', () => { - let popup; - const position = [0, 0]; + let popup + const position = [0, 0] renderIntoDocument( - {popup = e;}}> + Test Popup - ); + ) - expect(popup.leafletElement.options.position).toEqual(position); - }); + expect(popup.leafletElement.options.position).toEqual(position) + }) it('adds and removes the popup on the map', () => { - const openOn = jest.genMockFunction(); - const removeLayer = jest.genMockFunction(); + const openOn = jest.fn() + const removeLayer = jest.fn() - Leaflet.Map.prototype.removeLayer = removeLayer; + Leaflet.Map.prototype.removeLayer = removeLayer Leaflet.Popup.prototype.openOn = openOn class TestComponent extends Component { - constructor() { - super(); + constructor () { + super() this.state = { show: false, test: true, - }; + } } - componentDidMount() { - expect(openOn.mock.calls.length).toBe(0); - expect(removeLayer.mock.calls.length).toBe(0); - this.setState({show: true}); + componentDidMount () { + expect(openOn.mock.calls.length).toBe(0) + expect(removeLayer.mock.calls.length).toBe(0) + this.setState({show: true}) } - componentDidUpdate() { + componentDidUpdate () { if (this.state.test) { - expect(openOn.mock.calls[0][0]).toBe(this.refs.map.leafletElement); + expect(openOn.mock.calls[0][0]).toBe(this.refs.map.leafletElement) this.setState({ show: false, test: false, - }); - } - else { - expect(removeLayer.mock.calls[0][0]).toBeDefined(); + }) + } else { + expect(removeLayer.mock.calls[0][0]).toBeDefined() } } - render() { - const position = [0, 0]; + render () { + const position = [0, 0] const popup = this.state.show ? ( Test Popup - ) : null; + ) : null return ( {popup} - ); + ) } } - renderIntoDocument(); - }); -}); + renderIntoDocument() + }) +}) diff --git a/package.json b/package.json index 231f58f5..75069dfd 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "babel-cli": "^6.10.1", "babel-core": "^6.10.4", "babel-eslint": "^6.1.2", - "babel-jest": "^13.2.2", + "babel-jest": "^15.0.0", "babel-loader": "^6.2.4", "babel-plugin-dev-expression": "^0.2.1", "babel-plugin-lodash": "^3.2.4", @@ -57,16 +57,16 @@ "babel-preset-react": "^6.11.1", "babel-preset-stage-0": "^6.5.0", "eslint": "^3.1.1", - "eslint-config-standard": "^5.3.5", - "eslint-config-standard-jsx": "^2.0.0", - "eslint-config-standard-react": "^3.0.0", + "eslint-config-standard": "^6.0.0", + "eslint-config-standard-jsx": "^3.0.0", + "eslint-config-standard-react": "^4.0.0", "eslint-plugin-promise": "^2.0.0", - "eslint-plugin-react": "^5.2.2", + "eslint-plugin-react": "^6.2.0", "eslint-plugin-standard": "^2.0.0", - "jest-cli": "^13.2.3", + "jest-cli": "^15.1.1", "leaflet": "^0.7.7", - "lodash-webpack-plugin": "^0.9.2", - "onchange": "^2.5.0", + "lodash-webpack-plugin": "^0.10.0", + "onchange": "^3.0.0", "react": "^15.2.1", "react-addons-test-utils": "^15.2.1", "react-dom": "^15.2.1", @@ -76,13 +76,6 @@ }, "jest": { "collectCoverage": true, - "scriptPreprocessor": "/node_modules/babel-jest", - "unmockedModulePathPatterns": [ - "/node_modules/fbjs", - "/node_modules/jest-cli", - "/node_modules/lodash", - "/node_modules/react", - "/node_modules/react-dom" - ] + "scriptPreprocessor": "/node_modules/babel-jest" } } diff --git a/src/ScaleControl.js b/src/ScaleControl.js index 8b2138bb..490c395b 100644 --- a/src/ScaleControl.js +++ b/src/ScaleControl.js @@ -5,7 +5,7 @@ import { PropTypes } from 'react' import MapControl from './MapControl' -export default class ZoomControl extends MapControl { +export default class ScaleControl extends MapControl { static propTypes = { imperial: PropTypes.bool, maxWidth: PropTypes.number,