Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LayersControl does not pass map props to children #142

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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