Testing arcgis/core in React with Storybook

200
0
03-13-2024 12:21 AM
Bart
by
New Contributor

Hello 🙂

I am using @ArcGIS/core package in React web application. I also use Storybook for testing.

I have a case (multiple cases actually) when I subscribe to MapView (like through mapView.on('click', () => {...}) ) ) inside useEffect to react to occurred click events. So every time there is an event I am interested in, I set state through useState or send xstate event to my machine if needed. The way I do that doesn't matter that much, what matters is how I can test that behaviour... In the typical UI you use Testing Library utilities like screen.getByText() etc to grab a specific HTML element and simulate click through userEvent.click(), but when the map is one big canvas element, those selectors are useless. So in order to make everything testable I need to somehow emit the event on MapView instance. And it seems to me there is no way in v4 of @ArcGIS/core to do that - Solved: emit click event in 4.x - Esri Community.

So my question is how I should test my functionality where I use ArcGIS models like MapView? If I cannot use mapView.emit(), then how I can simulate the map click event in the specific place to make sure that for instance I use SketchViewModel properly and that my React components align with those events emitted by map clicks?

This is really critical IMHO because I cannot test my software which uses @ArcGIS/core package.

Thanks for response in advance 🙂

Tags (3)
0 Kudos
0 Replies