Skip to content

Commit 23bae28

Browse files
committed
Add README describing the package and usage
1 parent e9f567c commit 23bae28

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Google Maps Javascript API Stub
2+
3+
Google Maps Javascript API is exposed under the `window.google` namespace, and has an object structure that's fairly involved.
4+
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.
5+
It usually ends up adding noise to your tests, and obscuring their intent.
6+
7+
This package stubs out the `window.google` namespace, and all documented objects and methods of the Maps API under this namespace.
8+
All of the stubs are `noop`s and usually return an empty object, or an object with a sensible structure as appropriate.
9+
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.
10+
In addition, you can set up explicit expectations on specific Google Maps API calls when you are testing interactions with the Maps API.
11+
12+
Initial versions of this package stub out significant portions of the documented Maps API.
13+
Eventually this package will be versioned in lockstep with the Maps API versions (i.e. importing version `X` of this package will stub out version `X` of the Maps API).
14+
15+
## Usage
16+
- Install the package
17+
18+
`npm install --save-dev googlemaps-js-api-stub`
19+
20+
OR
21+
22+
`yarn add --dev googlemaps-js-api-stub`
23+
24+
- Import `googlemaps-js-api-stub` into your test
25+
26+
`import 'googlemaps-js-api-stub'`
27+
28+
OR
29+
30+
`require 'googlemaps-js-api-stub'`
31+
32+
- Optionally, set expectations on specific API calls as required
33+
34+
```javascript
35+
sinon.stub(window.google.Map, 'setZoom');
36+
expect(window.google.Map.setZoom).to.have.been.called
37+
```

0 commit comments

Comments
 (0)