Skip to content

mapbox component jest tests #311

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

Merged
merged 4 commits into from
Oct 10, 2022
Merged

Conversation

yen-tt
Copy link
Contributor

@yen-tt yen-tt commented Oct 7, 2022

added jest tests for Mapbox component, specifically for the two prop fields: getCoordinate and onDrag. The remaining props are best tested through storybook.

note that mapbox-gl is mocked as it seems to use some web browser functionality on initialization that is not supported in jest test environment (jsdom). Without mocking, jest would present an error Error: Failed to initialize WebGL..

  • tried third party libraries jest-webgl-canvas-mock and jest-canvas-mock still result in more window properties access related errors ([TypeError: e.window.Worker is not a constructor], which could be resolve by manually mocking Worker, [TypeError: this.target.addEventListener is not a function]...).
  • Looked into how pageJS test mapbox provider in their map component: the map wrapper component invoke a load function to construct a script tag from yext/components-tsx-maps and the assertions in the unit tests seem to check for the rendering of the wrapper component only and not waiting for the script to load. No content/interaction of the map was tested from my understanding.
  • Looked into how mapbox-gl-js does their own testing: they had a couple util files to set up the environment for their tests (mock requests, mock HtmlCanvas/WebLG in window object, etc.).

I decided this complexity is probably unnecessary to add to the repo but we can discuss if other may think differently. We can have jest strictly test new isolated functionalities added from the component and leave all the UI rendering and mapbox interaction to storybook tests.

SLAP-2222
TEST=auto

new jest tests passed

@yen-tt yen-tt requested a review from a team as a code owner October 7, 2022 20:59
@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2022

Current unit coverage is 89.12721893491124%
Current visual coverage is 73.77551020408163%
Current combined coverage is 89.64497041420118%

@yen-tt yen-tt requested a review from nmanu1 October 10, 2022 14:34
@yen-tt yen-tt merged commit 8c677c6 into feature/mapbox-component Oct 10, 2022
@yen-tt yen-tt deleted the dev/mapbox-jest-tests branch October 10, 2022 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants