├── .editorconfig ├── .eslintrc ├── .gitignore ├── .lintstagedrc ├── .prettierrc ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENCE.md ├── README.md ├── babel.config.js ├── demo └── src │ ├── demo.md │ ├── index.js │ └── routes.js ├── jest.config.js ├── nwb.config.js ├── package.json ├── src ├── index.js ├── index.test.js └── loadGoogleMapsSdk │ ├── index.js │ └── index.test.js └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | insert_final_newline = true 7 | trim_trailing_whitespace = true 8 | indent_style = space 9 | indent_size = 2 10 | 11 | [*.md] 12 | indent_size = 4 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | "env": { 4 | "amd": true, 5 | "es6": true, 6 | "jest/globals": true 7 | }, 8 | "plugins": ["jest", "prettier", "react"], 9 | "extends": [ 10 | "eslint:recommended", 11 | "plugin:jest/recommended", 12 | "plugin:react/recommended", 13 | "prettier" 14 | ], 15 | "globals": { 16 | "document": true, 17 | "window": true 18 | }, 19 | "settings": { 20 | "react": { 21 | "version": "detect" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | /coverage 3 | /demo/dist 4 | /es 5 | /lib 6 | /node_modules 7 | /umd 8 | npm-debug.log* 9 | yarn-error.log* 10 | -------------------------------------------------------------------------------- /.lintstagedrc: -------------------------------------------------------------------------------- 1 | { 2 | "*.js": [ 3 | "prettier --no-bracket-spacing --no-semi --trailing-comma=es5 --write", 4 | "git add" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "bracketSpacing": false, 3 | "semi": false, 4 | "trailingComma": "es5" 5 | } 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: node_js 4 | node_js: 8 5 | 6 | before_install: 7 | - npm install codecov 8 | 9 | after_success: 10 | - cat ./coverage/lcov.info | ./node_modules/.bin/codecov 11 | 12 | branches: 13 | only: 14 | - master 15 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # 4.3.0 - 2020-04-27 2 | 3 | - Added: Do not load google maps multiple times 4 | - Updated: Update dependencies 5 | 6 | # 4.2.5 - 2019-02-12 7 | 8 | - Updated: Update dependencies 9 | 10 | # 4.2.4 - 2019-02-07 11 | 12 | - Fixed: Remove warning 13 | 14 | # 4.2.3 - 2018-04-10 15 | 16 | - Updated: Move window.google initialisation 17 | 18 | # 4.2.2 - 2018-04-10 19 | 20 | - Fixed: Tests 21 | 22 | # 4.2.1 - 2018-04-10 23 | 24 | - Updated: Load GoogleMapsSdk in componentDidMount instead of componentWillMount 25 | 26 | # 4.2.0 - 2018-03-23 27 | 28 | - Add: Error message and loading state by @joshuaai 29 | 30 | # 4.1.0 - 2017-11-03 31 | 32 | - Removed: Useless wrapper 33 | 34 | # 4.0.1 - 2017-10-26 35 | 36 | - Added: Tests 37 | 38 | # 4.0.0 - 2017-10-25 39 | 40 | - Updated: Tranform Hight Order Component to React Component using a render prop 41 | - Added: CommonJS build 42 | - Added: ES6 build 43 | - Added: UMD build 44 | - Added: Demo page 45 | 46 | # 3.0.1 - 2017-07-03 47 | 48 | - Updated: Documentation 49 | 50 | # 3.0.0 - 2017-07-03 51 | 52 | - Updated: Deprecate v2.0.3 53 | 54 | # 2.0.3 - 2017-06-14 55 | 56 | - Updated: Render component even when google maps is not loaded yet 57 | 58 | # 2.0.2 - 2017-01-04 59 | 60 | - Updated: React peer dependency 61 | 62 | # 2.0.1 - 2016-11-21 63 | 64 | - Added: Handle non web-browser environments 65 | 66 | # 2.0.0 - 2016-10-24 67 | 68 | - Added: `little-loader` lib to fetch Google Map API 69 | - Added: `query-string` lib to transform params to query string 70 | - Updated: `package.json` description, author and dependencies 71 | - Updated: `.babelrc` 72 | - Updated: `.eslintrc` 73 | - Updated: `src/index.js` 74 | 75 | # 1.0.1 - 2015-09-11 76 | 77 | - Added: libraryTarget into Webpack config 78 | 79 | # 1.0.0 - 2015-09-08 80 | 81 | - Initial release 82 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | ## Prerequisites 4 | 5 | [Node.js](http://nodejs.org/) >= v4 must be installed. 6 | 7 | ## Installation 8 | 9 | - Running `yarn install` in the components's root directory will install everything you need for development. 10 | 11 | ## Demo Development Server 12 | 13 | - `yarn start` will run a development server with the component's demo app at [http://localhost:1190](http://localhost:1190) with hot module reloading. 14 | 15 | ## Linting 16 | 17 | - `yarn run lint` will lint the `src` and `demo/src` folders 18 | 19 | ## Running Tests 20 | 21 | - `yarn test` will run the tests once and produce a coverage report in `coverage/`. 22 | 23 | - `yarn run test:watch` will run the tests on every change. 24 | 25 | ## Building 26 | 27 | - `yarn run build` will build the component for publishing to npm and also bundle the demo app. 28 | 29 | - `yarn run clean` will delete built resources. 30 | 31 | > **Builds:** 32 | > * CommonJS build => `/lib`, 33 | > * ES6 modules build => `/es` 34 | > * UMD build => `/umd` 35 | > * Demo build => `/demo/dist` 36 | -------------------------------------------------------------------------------- /LICENCE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Cédric Delpoux 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # react-google-maps-loader 2 | 3 | [![npm package][npm-badge]][npm] 4 | [![Travis][build-badge]][build] 5 | [![Codecov][codecov-badge]][codecov] 6 | ![Module formats][module-formats] 7 | 8 | React Component to use google maps services into your react applications using a render prop. 9 | 10 | ## Getting started 11 | 12 | [![react-google-maps-loader](https://nodei.co/npm/react-google-maps-loader.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/react-google-maps-loader/) 13 | 14 | You can download `react-google-maps-loader` from the NPM registry via the `npm` or `yarn` commands 15 | 16 | ```shell 17 | yarn add react-google-maps-loader 18 | npm install react-google-maps-loader --save 19 | ``` 20 | 21 | If you don't use package manager and you want to include `react-google-maps-loader` directly in your html, you could get it from the UNPKG CDN 22 | 23 | ```html 24 | https://unpkg.com/react-google-maps-loader/dist/react-google-maps-loader.min.js. 25 | ``` 26 | 27 | You can also try the component's editable demo hands-on and install it from [bit.dev](https://bit.dev/cedricdelpoux/react-google-maps-loader/react-google-maps-loader?example=5d592e9f500b4e00146cca67). 28 | 29 | ## Usage 30 | 31 | ### Load Map Only 32 | 33 | This renders when the map is ready, with no loading state. 34 | 35 | ```javascript 36 | import React from "react" 37 | import ReactGoogleMapLoader from "react-google-maps-loader" 38 | 39 | const App = () => ( 40 | googleMaps &&
Google Maps is loaded !
} 46 | /> 47 | ) 48 | ``` 49 | 50 | ### Show Loading State 51 | 52 | You can show a custom loading state while the user is still online by using the error values. 53 | 54 | #### Error Values 55 | 56 | - `[String] Network Error` - if the user us offline. 57 | 58 | - `[String] SDK Authentication Error` - if there is a problem loading Google maps due to incorrect keys, going over quota or one of the errors listed in the [Error Messages Documentation](https://developers.google.com/maps/documentation/javascript/error-messages). 59 | 60 | - `undefined` - map loaded correctly. 61 | 62 | ```js 63 | import React from "react" 64 | import ReactGoogleMapLoader from "react-google-maps-loader" 65 | 66 | const App = () => ( 67 | 73 | googleMaps ? ( 74 |
75 | {/*Show a custom error if SDK Authentication Error. See N/B 2 below.*/} 76 | {error ? error : "Google Maps is loaded !"} 77 |
78 | ) : ( 79 |
80 | {/*Check for network error so loading state ends if user lost connection.*/} 81 | {error === "Network Error" ? ( 82 |

{error}

83 | ) : ( 84 |

isLoading...

85 | )} 86 |
87 | ) 88 | } 89 | /> 90 | ) 91 | ``` 92 | 93 | N/B: 94 | 95 | 1. The Google Maps API does not provide errors in the callback but logs them to the console. We grouped all Google Maps errors not related to network connectivity as `SDK Authentication Error`. Check the console if you get this. 96 | 97 | 2. `googleMaps` always loads as long as there is no `Network Error` and the previous state is not cached. So, handle `SDK Authentication Errors` (See 1. above) in the `googleMaps` part of the conditional rendering as shown in the code above. 98 | 99 | ## Demo 100 | 101 | See [Demo page][github-page] 102 | 103 | ## Contributing 104 | 105 | - ⇄ Pull/Merge requests and ★ Stars are always welcome. 106 | - For bugs and feature requests, please [create an issue][github-issue]. 107 | - Pull requests must be accompanied by passing automated tests (`npm test`). 108 | 109 | See [CONTRIBUTING.md](./CONTRIBUTING.md) guidelines 110 | 111 | ## Changelog 112 | 113 | See [changelog](./CHANGELOG.md) 114 | 115 | ## License 116 | 117 | This project is licensed under the MIT License - see the [LICENCE.md](./LICENCE.md) file for details 118 | 119 | [npm-badge]: https://img.shields.io/npm/v/react-google-maps-loader.svg?style=flat-square 120 | [npm]: https://www.npmjs.org/package/react-google-maps-loader 121 | [build-badge]: https://img.shields.io/travis/cedricdelpoux/react-google-maps-loader/master.svg?style=flat-square 122 | [build]: https://travis-ci.org/cedricdelpoux/react-google-maps-loader 123 | [codecov-badge]: https://img.shields.io/codecov/c/github/cedricdelpoux/react-google-maps-loader.svg?style=flat-square 124 | [codecov]: https://codecov.io/gh/cedricdelpoux/react-google-maps-loader 125 | [module-formats]: https://img.shields.io/badge/module%20formats-umd%2C%20cjs%2C%20esm-green.svg?style=flat-square 126 | [github-page]: https://cedricdelpoux.github.io/react-google-maps-loader 127 | [github-issue]: https://github.com/cedricdelpoux/react-google-maps-loader/issues/new 128 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line 2 | module.exports = { 3 | presets: ['@babel/preset-env', '@babel/preset-react'], 4 | }; 5 | -------------------------------------------------------------------------------- /demo/src/demo.md: -------------------------------------------------------------------------------- 1 | ## Code 2 | 3 | ```javascript 4 | import ReactGoogleMapLoader from "react-google-maps-loader" 5 | import ReactGoogleMap from "react-google-map" 6 | 7 | const YourComponent = () => ( 8 | 14 | googleMaps && ( 15 |
16 | 21 |
22 | ) 23 | } 24 | /> 25 | ) 26 | ``` 27 | 28 | ## Demo 29 | -------------------------------------------------------------------------------- /demo/src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | import ReactDemoPage from "react-demo-page" 3 | import {render} from "react-dom" 4 | import pkg from "../../package.json" 5 | import routes from "./routes" 6 | 7 | const header = { 8 | title: pkg.name, 9 | buttons: [ 10 | {label: "Github", url: pkg.homepage}, 11 | {label: "Npm", url: `https://www.npmjs.com/package/${pkg.name}`}, 12 | {label: "Download", url: `${pkg.homepage}/archive/master.zip`}, 13 | ], 14 | } 15 | 16 | const footer = { 17 | author: pkg.author, 18 | } 19 | 20 | const Demo = () => ( 21 | 28 | ) 29 | 30 | // eslint-disable-next-line 31 | render(, document.querySelector("#demo")) 32 | -------------------------------------------------------------------------------- /demo/src/routes.js: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | import ReactGoogleMap from "react-google-map" 3 | import readmeHtml from "../../README.md" 4 | import ReactGoogleMapLoader from "../../src" 5 | import demoHtml from "./demo.md" 6 | 7 | const routes = [ 8 | { 9 | path: "/", 10 | exact: true, 11 | component: ( 12 |
13 |
14 | 20 | googleMaps ? ( 21 |
22 | {error && error} 23 | 28 |
29 | ) : ( 30 |
31 | {error === "Network Error" ? ( 32 |

{error}

33 | ) : ( 34 |

isLoading...

35 | )} 36 |
37 | ) 38 | } 39 | /> 40 |
41 | ), 42 | label: "Demo", 43 | }, 44 | { 45 | path: "/readme", 46 | html: readmeHtml, 47 | label: "Read me", 48 | }, 49 | ] 50 | 51 | export default routes 52 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | // eslint-disable-next-line 2 | module.exports = { 3 | coverageDirectory: "./coverage/", 4 | collectCoverage: true, 5 | moduleNameMapper: { 6 | "\\.(css)$": "/node_modules/jest-css-modules" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /nwb.config.js: -------------------------------------------------------------------------------- 1 | var extraWebpackConfig = { 2 | module: { 3 | rules: [ 4 | { 5 | test: /\.js$/, 6 | enforce: "pre", 7 | loader: "eslint-loader", 8 | include: /src/, 9 | }, 10 | { 11 | test: /\.md$/, 12 | loader: "html-loader!markdown-loader", 13 | exclude: /node_modules/, 14 | }, 15 | ], 16 | }, 17 | } 18 | 19 | // eslint-disable-next-line 20 | module.exports = { 21 | type: "react-component", 22 | polyfill: false, 23 | npm: { 24 | cjs: true, 25 | esModules: true, 26 | umd: { 27 | global: "ReactDemoPage", 28 | externals: { 29 | react: "React", 30 | "prop-types": "PropTypes", 31 | }, 32 | }, 33 | }, 34 | webpack: { 35 | extra: extraWebpackConfig, 36 | }, 37 | } 38 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-google-maps-loader", 3 | "version": "4.3.0", 4 | "author": { 5 | "name": "Cédric Delpoux", 6 | "email": "cedric.delpoux@gmail.com" 7 | }, 8 | "description": "React component to use google maps services into your react applications using a render prop", 9 | "files": [ 10 | "css", 11 | "es", 12 | "lib", 13 | "umd" 14 | ], 15 | "homepage": "https://github.com/cedricdelpoux/react-google-maps-loader#readme", 16 | "keywords": [ 17 | "react", 18 | "google", 19 | "maps", 20 | "googlemaps", 21 | "loader", 22 | "decorator" 23 | ], 24 | "license": "MIT", 25 | "main": "lib/index.js", 26 | "module": "es/index.js", 27 | "style": "umd/index.css", 28 | "repository": { 29 | "type": "git", 30 | "url": "git+https://github.com/cedricdelpoux/react-google-maps-loader.git" 31 | }, 32 | "scripts": { 33 | "build": "nwb build-react-component", 34 | "clean": "nwb clean-module && nwb clean-demo", 35 | "deploy": "gh-pages -d demo/dist", 36 | "lint": "eslint src demo/src", 37 | "precommit": "lint-staged", 38 | "prepublish": "yarn run clean && yarn run build", 39 | "start": "nwb serve-react-demo --port 1190", 40 | "test": "jest --colors --no-cache", 41 | "test:watch": "yarn test -- --watch" 42 | }, 43 | "dependencies": { 44 | "little-loader": "~0.2.0", 45 | "prop-types": "^15.7.2", 46 | "query-string": "^6.12.1" 47 | }, 48 | "devDependencies": { 49 | "@babel/core": "^7.9.0", 50 | "@babel/preset-env": "^7.9.5", 51 | "babel-eslint": "^10.1.0", 52 | "babel-jest": "^25.4.0", 53 | "enzyme": "^3.11.0", 54 | "enzyme-adapter-react-16": "^1.15.2", 55 | "eslint": "^6.8.0", 56 | "eslint-config-prettier": "^6.11.0", 57 | "eslint-loader": "^4.0.2", 58 | "eslint-plugin-jest": "^23.8.2", 59 | "eslint-plugin-prettier": "^3.1.3", 60 | "eslint-plugin-react": "^7.19.0", 61 | "gh-pages": "^2.2.0", 62 | "html-loader": "^1.1.0", 63 | "husky": "^4.2.5", 64 | "jest": "^25.4.0", 65 | "jest-css-modules": "^2.1.0", 66 | "lint-staged": "^10.1.7", 67 | "markdown-loader": "^5.1.0", 68 | "nwb": "^0.24.5", 69 | "prettier": "^2.0.5", 70 | "react": "^16.13.1", 71 | "react-demo-page": "^0.3.6", 72 | "react-dom": "^16.13.1", 73 | "react-google-map": "^3.1.0", 74 | "react-test-renderer": "^16.13.1" 75 | }, 76 | "peerDependencies": { 77 | "react": ">=16.8.0", 78 | "react-dom": ">=16.8.0" 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import PropTypes from "prop-types" 2 | import React from "react" 3 | import loadGoogleMapsSdk from "./loadGoogleMapsSdk" 4 | 5 | class GoogleMapsLoader extends React.Component { 6 | constructor() { 7 | super() 8 | 9 | this._isMounted = false 10 | this.state = { 11 | googleMaps: null, 12 | error: null, 13 | } 14 | } 15 | 16 | componentDidMount() { 17 | this._isMounted = true 18 | const {params} = this.props 19 | loadGoogleMapsSdk( 20 | params, 21 | ({googleMaps, error}) => 22 | this._isMounted && this.setState({googleMaps, error}) 23 | ) 24 | } 25 | 26 | componentWillUnmount() { 27 | this._isMounted = false 28 | } 29 | 30 | render() { 31 | const {googleMaps, error} = this.state 32 | const {render} = this.props 33 | return render(googleMaps, error) 34 | } 35 | } 36 | 37 | GoogleMapsLoader.propTypes = { 38 | params: PropTypes.shape({ 39 | key: PropTypes.string.isRequired, 40 | libraries: PropTypes.string, 41 | }).isRequired, 42 | render: PropTypes.func.isRequired, 43 | } 44 | 45 | export default GoogleMapsLoader 46 | -------------------------------------------------------------------------------- /src/index.test.js: -------------------------------------------------------------------------------- 1 | import {configure, mount} from "enzyme" 2 | import Adapter from "enzyme-adapter-react-16" 3 | import React from "react" 4 | import GoogleMapsLoader from "./index" 5 | 6 | configure({adapter: new Adapter()}) 7 | 8 | const html = "Loaded" 9 | const params = { 10 | key: "AIzaSyCLTirc_kwH5fV0RkzOIH_cP5J9SJHW2QA", 11 | } 12 | 13 | const GoogleMapsLoaderFixture = ( 14 | googleMaps &&
{html}
} 17 | /> 18 | ) 19 | 20 | beforeAll(() => { 21 | const script = document.createElement("script") 22 | document.body.appendChild(script) 23 | }) 24 | 25 | describe("GoogleMapsLoader", () => { 26 | it("renders", () => { 27 | mount(GoogleMapsLoaderFixture) 28 | }) 29 | }) 30 | -------------------------------------------------------------------------------- /src/loadGoogleMapsSdk/index.js: -------------------------------------------------------------------------------- 1 | import load from "little-loader" 2 | import qs from "query-string" 3 | 4 | const GOOGLE_MAP_PLACES_API = "https://maps.googleapis.com/maps/api/js" 5 | const NOT_LOADED = 0 6 | const LOADING = 1 7 | const LOADED = 2 8 | 9 | const queue = [] 10 | let state = NOT_LOADED 11 | let googleMaps = null 12 | let error = null 13 | 14 | function loadGoogleMapsSdk(params, callback) { 15 | if (typeof window !== "undefined") { 16 | window.gm_authFailure = () => { 17 | callback({googleMaps, error: "SDK Authentication Error"}) 18 | } 19 | 20 | if (state === LOADED) { 21 | callback({googleMaps, error}) 22 | } else if (state === LOADING) { 23 | queue.push(callback) 24 | } else if (window.google && window.google.maps) { 25 | state = LOADED 26 | googleMaps = window.google.maps 27 | callback({googleMaps, error}) 28 | } else { 29 | state = LOADING 30 | queue.push(callback) 31 | 32 | load(`${GOOGLE_MAP_PLACES_API}?${qs.stringify(params)}`, (err) => { 33 | state = LOADED 34 | error = err ? "Network Error" : null 35 | googleMaps = window.google ? window.google.maps : null 36 | 37 | while (queue.length > 0) { 38 | queue.pop()({googleMaps, error}) 39 | } 40 | }) 41 | } 42 | } 43 | } 44 | 45 | export default loadGoogleMapsSdk 46 | -------------------------------------------------------------------------------- /src/loadGoogleMapsSdk/index.test.js: -------------------------------------------------------------------------------- 1 | import loadGoogleMapsSdk from "./index" 2 | 3 | const params = { 4 | key: "AIzaSyCLTirc_kwH5fV0RkzOIH_cP5J9SJHW2QA", 5 | libraries: "places,geometry", 6 | } 7 | 8 | const fakeParams = { 9 | key: "1234555666", 10 | libraries: "places,geometry", 11 | } 12 | 13 | beforeAll(() => { 14 | const script = document.createElement("script") 15 | document.body.appendChild(script) 16 | }) 17 | 18 | describe("loadGoogleMapsSdk", () => { 19 | test("Loads places and geometry libraries", (done) => { 20 | function callback({googleMaps}) { 21 | expect(googleMaps).toEqual( 22 | expect.objectContaining({ 23 | places: expect.anything(), 24 | geometry: expect.anything(), 25 | }) 26 | ) 27 | done() 28 | } 29 | 30 | loadGoogleMapsSdk(params, callback) 31 | }) 32 | 33 | test("Returns Google Maps Authntication Error", (done) => { 34 | function callback({error}) { 35 | window.setTimeout(() => { 36 | expect(error).toEqual("SDK Authentication Error") 37 | }, 1000) 38 | done() 39 | } 40 | 41 | loadGoogleMapsSdk(fakeParams, callback) 42 | }) 43 | 44 | test("Returns Network Error", (done) => { 45 | function callback({error}) { 46 | console.log("callback") 47 | window.setTimeout(() => { 48 | expect(error).toBe("Network Error") 49 | }, 1000) 50 | done() 51 | } 52 | 53 | loadGoogleMapsSdk(null, callback) 54 | }) 55 | }) 56 | --------------------------------------------------------------------------------