Skip to content

Commit

Permalink
LayersControl does not pass map props to children (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dahlgren authored and PaulLeCam committed Apr 17, 2016
1 parent f7037b9 commit 018f1f9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
40 changes: 40 additions & 0 deletions __tests__/LayersControl.js
Original file line number Diff line number Diff line change
@@ -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 = '<div id="test"></div>';

class ChildComponent extends React.Component {
static propTypes = {
map: React.PropTypes.instanceOf(Leaflet.Map)
};

componentWillMount() {
expect(this.props.map).toBeDefined();
}

render() {
return null;
}
}

const component = (
<Map>
<LayersControl>
<LayersControl.Overlay checked name='test'>
<ChildComponent />
</LayersControl.Overlay>
</LayersControl>
</Map>
);

render(component, document.getElementById('test'));
});
});
3 changes: 2 additions & 1 deletion lib/LayersControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ var ControlledLayer = function (_Component) {
layerContainer: {
addLayer: this.addLayer.bind(this),
removeLayer: this.removeLayer.bind(this)
}
},
map: this.props.map
});
}
}]);
Expand Down
1 change: 1 addition & 0 deletions src/LayersControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ControlledLayer extends Component {
addLayer: ::this.addLayer,
removeLayer: ::this.removeLayer,
},
map: this.props.map,
});
}
}
Expand Down

0 comments on commit 018f1f9

Please sign in to comment.