7

I'm downloading the google maps API v3 via a script tag, and I'm adding the dependency to my modules with the following (relevant) package.json configuration:

"browserify-shim": {
   "google": "global:google"
}

And I can add the dependency in my files with the following:

var google = require('google');

When I run my code in the browser, it works fine. The problem is, when I run my tests with Jest, it tells me that it can't find the 'google' module:

Error: /src/app/assets/javascripts/__tests__/helpers-test.js: Cannot find module 'google' from '/src/app/assets/javascripts/__tests__'

Note:

This dependency is being required in the file that I'm testing, not the test itself. I find this confusing since I thought that Jest mocks all dependencies unless it is specified otherwise, but from what I can see, it first needs to correctly satisfy the dependencies before mocking.

Any ideas of what am I missing or what approach should I take?

Bhavesh Odedra
  • 10,990
  • 12
  • 33
  • 58
aleandros
  • 196
  • 1
  • 7

1 Answers1

0

You'll need to alias 'google' properly in your package.json, see here.

Thorsten Lorenz
  • 11,781
  • 8
  • 52
  • 62
  • Maybe there's something I'm not understanding about aliases. In the link you provided, a file is used in the aliases example, but the google maps api is loaded via a ascript tag (which I can't just download since it only downloads the missing components via more script tags). – aleandros Apr 21 '15 at 21:21