-
Notifications
You must be signed in to change notification settings - Fork 893
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
Map container not found when testing Map parent component #246
Comments
@thomasthiebaud it won't matter where the react-leaflet map component is nested in your structure. The only way to get react-leaflet map components to mount with enzyme is by attaching it to an existing element which has been inserted in the document body in jsdom or some other document-like thing. @dkreft I did some research and it appears that the core issue is that Leaflet scans the document body to try to find the element to modify, but doesn't find it because of the following: enzyme attempts to mount by calling |
This seem to be an issue with mocha/enzyme, same as in #204, as it works as expected in browsers. |
Ok, thank for the answer. I will try to investigate. |
Based on #246 (comment) the solution could be to use attach as mount option.
|
I see the same behavior with describe('the `Map` component', () => {
let component = Renderer.create(<Map />),
tree = component.toJSON()
test('renders correctly with nothing passed', () => {
expect(tree).toMatchSnapshot()
})
}) I still have to try @simeonackermann's workaround with |
@simeonackermann your example worked, thanks! @PaulLeCam would you accept a PR to add documentation on this? Any advice on an existing document to edit from here would be appreciated: https://github.com/PaulLeCam/react-leaflet/tree/master/docs Otherwise, I can just add a new file called |
Asana Task: Dev cleanup: Use react-leaflet package https://app.asana.com/0/1152340551558956/1153855588392657 It's mostly done and working But tests are failing with "Map container not found" See PaulLeCam/react-leaflet#246 I don't know how to fix that and need to move on to other tasks so leaving this unfinished for now.
For lost googlers: you may encounter similar questions when using Jest+Storyshots. I am looking for fix in this precise scenario. |
Did you manage to fix this with Snapshots? That explains the issue I experience with Storyshots but I am not sure how far I can customize it, since most of the snapshot operations are automated. Edit: alternate solution for Storyshots using |
Note: For the tests related to drawing markers / shapes on the map, I intended to introduce snapshot tests. However, I kept running into "Map container not found" (issue)[PaulLeCam/react-leaflet#246]. Opted to keep the test as finding the specified classname in the given HTML as that is what the original tests were doing anyway.
…testing library (#1726) * refactor(LadderPage.test): convert enzyme tests to react testing library * refactor(Ladder.test): replace enzyme tests with react-testing-library * refactor: A few more straightforward enzyme conversions * refactor: a few more enzyme tests * revert swings test changes * refactor: use title intead of test-id for buttons * fix: title case for titles * refactor: more enzyme => react-testing-library tests * refactor: header tests * refactor: settings page tests * refactor: routeVariantName tests * refactor: Shuttle picker tests * refactor: searchPage enzyme tests => react testing library * refactor: map tests using react-testing library Note: For the tests related to drawing markers / shapes on the map, I intended to introduce snapshot tests. However, I kept running into "Map container not found" (issue)[PaulLeCam/react-leaflet#246]. Opted to keep the test as finding the specified classname in the given HTML as that is what the original tests were doing anyway. * refactor: late view tests using react-testing-library * fix: resolve console warnings in minischedule tests * fix: searchPage tests no longer log console warnings I'm not really sure why simply reordering the tests did the trick. I suspect is has something to do with how the now last test uses the StateDispatchProvider or something that wasn't clearing properly between tests, but I'm not totally sure. * refactor: cleanup based on feedback * doc: add comments for lateView tests * fix(ladderPage.test): use title instead of testId * fix(lateView.test): make sure to test that all boxes are unselected * refactor: toBeTruthy => toBeInTheDocument for affectedwq react-testing-library tests * test: lateView.test updates Co-authored-by: Brady <kbrady@CTD24877KBRADY.local>
Please make sure to check the following boxes before submitting an issue. Thanks!
Expected behavior
Inside a
mocha
test usingenzyme
I expect to be able to mount the wrapper a component of my map without having anMap container not found.
Actual behavior
Map container not found.
Steps to reproduce
Given this component
I would like to
mount
the component usingenzyme.mount
function like thiswithout having the
Map container not found.
error.I already checked this issue #204, but this is not the same because I trying a parent component, not directly the map component.
The text was updated successfully, but these errors were encountered: