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

Uncaught (in promise) Error: "layer.canvas" not properly defined #110

Open
dig22 opened this issue Nov 2, 2021 · 4 comments · Fixed by #169
Open

Uncaught (in promise) Error: "layer.canvas" not properly defined #110

dig22 opened this issue Nov 2, 2021 · 4 comments · Fixed by #169

Comments

@dig22
Copy link

dig22 commented Nov 2, 2021

image

I'm getting this error, please advice

@alex-oko
Copy link

have you been able to find a solution to the problem?

@robopzet
Copy link

I get the same error in a browser using the browser build of Leaflet.glify, glify-browser.js.

This is how the map is created:

L.map('map', {maxZoom: 18, minZoom: 8, preferCanvas: true})

The error occurs when a layer with GeoJSON is created using this map:

L.glify.points({
    map,
    data: {
        features    : pts,
        type        : 'FeatureCollection',
    },
    size: 5
})

pts is an array of GeoJSON Point features, which can be processed by L.geoJSON from Leaflet.

@charlieforward9
Copy link
Collaborator

charlieforward9 commented Dec 1, 2024

+1. normal functionality in dev, throws during testing using vitest jsdom environment.

@charlieforward9
Copy link
Collaborator

charlieforward9 commented Dec 5, 2024

This error is thrown due to the CanvasOverlay class. If you remove one of the jest.mock("../canvas-overlay"); lines from one of the glify test files, you'll see this error.

I have tried mocking the CanvasOverlay class in every way possible vi.mock("canvas-overlay"), vi.mock("leaflet.glify" ...), vi.mock("leaflet", ...), with no success. I would like to be able to test as soon as possible so any help would go a long ways here.

As I brainstorm workarounds, one idea is to re-ship this package so that dependent packages could access its "internals" more intuitively, specifically for mocking.

Ex. making this possible

 vi.mock("leaflet.glify", async (importOriginal) => {
    const mod = await importOriginal<typeof import("leaflet.glify")>();
    return {
       ...mod, 
       CanvasOverlay: ... //mock the canvas overlay here
    }
 });

Another idea, if possible, would be to refactor the CanvasOverlay class to respect testing environments by default, so that dependent packages do not need to worry about this, if that is possible.

RFC @robertleeplummerjr @Liu-Eroteme @trafficonese

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 a pull request may close this issue.

4 participants