ReferenceError: google is not defined
See original GitHub issueNot sure if this is related to this repo, or Jest. But I’m getting this error when running my test:
ReferenceError: google is not defined
at GoogleAutoComplete.componentDidMount (src/components/GoogleAutoComplete/index.js:38:31)
I have a script tag before my closing body tag that loads the google API. But apparently that’s not loaded into the test environment.
So I download that google api file and put it in my project directory under test/google.js.
I then tried to configure jest to load that file in my package.json:
{
"name": "web-app",
"jest": {
"setupTestFrameworkScriptFile": "test/google.js"
}
...
I also tried using setupFiles
:
{
"name": "web-app",
"jest": {
"setupFiles": [
"test/google.js"
],
...
Neither of which seem to be loading the file. I also tried loading a file that doesn’t exist and it didn’t throw any errors, which makes me wonder if create-react-app
is even loading jest config from package.json.
What’s the correct way to load google into the test environment? Is this a bug, or am I over locking something?
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
ReferenceError: google is not defined - Stack Overflow
I just noticed that in Google Chrome's Javascript console: it gives the following error: [blocked] The page at mypage.com/GoogleMapPage.aspx ran ...
Read more >Uncaught ReferenceError: google is not defined - MSDN
Usually this type of error is due to forgetting to reference a JavaScript library or trying to access a library object before the...
Read more >ReferenceError:'google' is undefined - Geopointe Help Center
If this error message appears while trying to access our map page, it means that Google is being blocked, either by the browser...
Read more >google is not defined - ionic v3.9.2, angular v5.2.11
Hello guys, i know this error is pretty common but i still have no idea which part did i do wrong. i already...
Read more >ReferenceError: google is not defined - Stork's Nest
My task is to create a Google Maps component without using any node module helper.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This worked for me.
src/setupTests.js
src/App.js
You’d have to either add some mock methods to the class as you use them, or switch to shallow rendering for testing so that
componentDidMount
never fires.If you need to access a global, access it explicitly as
window.google
. This is better than a mix of implicit globals scattered around the code.