JSPM

googlemaps-js-api-stub

3.61.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 439
  • Score
    100M100P100Q111553F
  • License ISC

Google Maps Javascript API Stub

Package Exports

  • googlemaps-js-api-stub
  • googlemaps-js-api-stub/stub.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (googlemaps-js-api-stub) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Google Maps Javascript API Stub

Google Maps Javascript API is exposed under the window.google namespace, and has an object structure that's fairly involved. This makes testing of components and other UI logic that depend on the Maps API a bit inconvenient, since you would inevitably have to stub out quite a few of the Maps API objects and method calls in your tests, even for fairly trivial usages. It usually ends up adding noise to your tests, and obscuring their intent.

This package stubs out the window.google namespace, and all documented objects and methods of the Maps API under this namespace. All of the stubs are noops and usually return an empty object, or an object with a sensible structure as appropriate. Importing this package into your tests will let you focus on testing your component and UI logic without having to worry about details of the Maps API. In addition, you can set up explicit expectations on specific Google Maps API calls when you are testing interactions with the Maps API.

Usage

  • Install the package

    npm install --save-dev googlemaps-js-api-stub

    OR

    yarn add --dev googlemaps-js-api-stub

  • Import googlemaps-js-api-stub into your test

    import 'googlemaps-js-api-stub'

    OR

    require 'googlemaps-js-api-stub'

  • Optionally, set expectations on specific API calls as required

sinon.stub(window.google.Map, 'setZoom');
expect(window.google.Map.setZoom).to.have.been.called