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

angular-mocks tricks Leaflet.GeometryUtil into thinking modules are available #78

Open
ReeseJones opened this issue Aug 15, 2018 · 0 comments

Comments

@ReeseJones
Copy link

image

I am setting up unit tests using angular 1, karma and jasmine. All our modules and plugins and scripts are statically included. When using jasmine and angular-mocks module is defined in the window scope. So when leaflet.GeometryUtil tries to add itself to leaflet it assumes module.export will exist (because the module object is defined), but it doesn't exist. In my case I expect it to install itself to a global L that is statically included, and not required.

we are using a few other leaflet plugins, but this seems to be the only one with this problem.

Perhaps you can look to see what these ones are doing when performing the // Packaging/modules magic dance.
Leaflet-semicircle
Leaflet-heatmap
Leaflet.markercluster

this is what the heatmap plugin is doing:

  // Supports UMD. AMD, CommonJS/Node.js and browser context
  if (typeof module !== "undefined" && module.exports) {
    module.exports = factory(
      require('heatmap.js'),
      require('leaflet')
    );
  } else if (typeof define === "function" && define.amd) {
    define(['heatmap.js', 'leaflet'], factory);
  } else {
    // browser globals
    if (typeof window.h337 === 'undefined') {
      throw new Error('heatmap.js must be loaded before the leaflet heatmap plugin');
    }
    if (typeof window.L === 'undefined') {
      throw new Error('Leaflet must be loaded before the leaflet heatmap plugin');
    }
    context[name] = factory(window.h337, window.L);
  }

I think an extra check for the fully qualified module.exports would solve my problem.
Why they put that in the global scope to begin with, I am not sure.

I cant upgrade frameworks for business reasons.

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

1 participant