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

Jest throws error when using Drawing Library #274

Closed
gluengenKmart opened this issue Jun 8, 2022 · 2 comments
Closed

Jest throws error when using Drawing Library #274

gluengenKmart opened this issue Jun 8, 2022 · 2 comments
Assignees

Comments

@gluengenKmart
Copy link

gluengenKmart commented Jun 8, 2022

We are attempting to write Jest tests with a map component that is using the google maps api drawing library

<LoadScript googleMapsApiKey={api_key} libraries={['drawing']}>
              ..
</LoadScript>
<GoogleMap
              mapContainerStyle={containerStyle}
              zoom={20}
              center={center}
              options={{ streetViewControl: false, mapTypeControl: false }}
            >
              <Marker position={center} />
              <Polygon
                paths={parseBoundary(centreBoundary?.coordinates).map((pt) => ({ lat: pt[0], lng: pt[1] }))}
                options={storeOptions}
              />
              <Polygon
                paths={parseBoundary(centreBoundary?.coordinates).map((pt) => ({ lat: pt[0], lng: pt[1] }))}
                options={centreOptions}
              />
              <DrawingManager
                onPolygonComplete={onCentrePolygonComplete}
                options={{ drawingControl: false, drawingMode: 'polygon' as OverlayType }}
              />
            </GoogleMap>

but when the component is accessed in the jest test

test('Should show dialog when button is pressed', async () => {
    renderWithClient(<MapPage />);
    const btn = await screen.findByRole('button', { name: /Show Map/i });
    btn.click();
    expect(await screen.findAllByText(/Click on the map/)).toBeTruthy();
  });

it throws the following error:

Invariant Violation: Did you include prop libraries={['drawing']} in the URL? undefined

@gluengenKmart gluengenKmart added triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jun 8, 2022
@stuaylward
Copy link

I agree, this library seems to be missing the entire DrawingManager in it's mocks?

@usefulthink
Copy link
Contributor

A feature request to add the drawingLibrary was added as #521. Besides that I don't see anything actionable for us here.

As for the original bug-report, I can't really tell where that error-message is coming from, but it coming from the implementation of the <GoogleMap> component seems reasonable. Unless that is the component you are developing and testing, I would advise to mock the entire component instead of trying to mock the Google Maps API and all it's interactions with the <GoogleMap> component.

The mocks provided here are really only useful if you are testing code that directly interacts with the Google Maps API, in which case there's no real alternative.

@usefulthink usefulthink removed type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. triage me I really want to be triaged. labels Sep 29, 2023
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

No branches or pull requests

4 participants