In my useEffect
hook I initialise a Leaflet map. It works all fine. But in the test it says "Map container not found.". To confirm I tried console.log(document.getElementById('mapid'))
. It finds the element when I run my app, but also not in the test. The DOM seems to be not yet rendered when I try to access it in useEffect
.
This is my useEffect code:
useEffect(() => {
console.log(document.getElementById('mapid'))
map.current = Leaflet.map('mapid').setView([46.378333, 13.836667], 12)
}, [])
And this the according test:
describe('initialise map', () => {
it('render map', () => {
const MapComponent = () => <Provider store={store}><Map /></Provider>
const component = mount(<MapComponent />)
expect.some.really.unexpected.things
})
})
How can I access the DOM in useEffect
when testing?