From 076df3a40a1da16d2a502870aaf56346de90a812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Dahlgren?= Date: Sat, 16 Apr 2016 15:40:52 +0200 Subject: [PATCH] LayersControl does not pass map props to children --- __tests__/LayersControl.js | 40 ++++++++++++++++++++++++++++++++++++++ lib/LayersControl.js | 3 ++- src/LayersControl.js | 1 + 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 __tests__/LayersControl.js diff --git a/__tests__/LayersControl.js b/__tests__/LayersControl.js new file mode 100644 index 00000000..98e12192 --- /dev/null +++ b/__tests__/LayersControl.js @@ -0,0 +1,40 @@ +import Leaflet from 'leaflet'; +import React from 'react'; +import { render } from 'react-dom'; + +jest.autoMockOff(); + +const LayersControl = require('../src/LayersControl').default; +const Map = require('../src/Map').default; + +describe('LayersControl', () => { + it('passes its `map` prop to its children', () => { + document.body.innerHTML = '
'; + + class ChildComponent extends React.Component { + static propTypes = { + map: React.PropTypes.instanceOf(Leaflet.Map) + }; + + componentWillMount() { + expect(this.props.map).toBeDefined(); + } + + render() { + return null; + } + } + + const component = ( + + + + + + + + ); + + render(component, document.getElementById('test')); + }); +}); diff --git a/lib/LayersControl.js b/lib/LayersControl.js index 6b454b0e..b0b6a26b 100644 --- a/lib/LayersControl.js +++ b/lib/LayersControl.js @@ -89,7 +89,8 @@ var ControlledLayer = function (_Component) { layerContainer: { addLayer: this.addLayer.bind(this), removeLayer: this.removeLayer.bind(this) - } + }, + map: this.props.map }); } }]); diff --git a/src/LayersControl.js b/src/LayersControl.js index 084de7c5..1f190e75 100644 --- a/src/LayersControl.js +++ b/src/LayersControl.js @@ -43,6 +43,7 @@ class ControlledLayer extends Component { addLayer: ::this.addLayer, removeLayer: ::this.removeLayer, }, + map: this.props.map, }); } }