When trying to get our unit tests running using Karma, I got the following error message:
“google is not defined”
Inside our application we are calling the google map API. During the tests the google map library cannot be found resulting in the error message above.
To fix it, we have to add this library to the files section in our karma.conf.js file:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function (config) { | |
config.set({ | |
basePath: '', | |
frameworks: ['jasmine', '@angular-devkit/build-angular'], | |
plugins: [ | |
require('karma-jasmine'), | |
require('karma-chrome-launcher'), | |
require('karma-jasmine-html-reporter'), | |
require('karma-coverage-istanbul-reporter'), | |
require('@angular-devkit/build-angular/plugins/karma') | |
], | |
files: [ | |
'https://maps.google.com/maps/api/js?key=<removed>&libraries=places' | |
] | |
}); | |
} |