async.js - RequireJS does not accept URL`s in the config`s paths declaration -


i want inject google way can inject own google mock in runner.js unit testing not want http calls.

 paths: {         lib: 'lib',                 async: 'lib/async',         google: 'async!http://maps.google.com/maps/api/js?sensor=false'     },  define(['google'], function(google) {  }); 

google undefined.

when use define works:

define(['async!http://maps.google.com/maps/api/js?sensor=false'], function(google) {      }); 

but can not use way because goodle hardcoded string in production code. way can not inject own google mock in unit test in runner.js path definition...

why first way not work?

google libraries not implement module pattern. expose functionality global google variable. in mock library mock on globally accessible google variable. workaround include shim configuration when loaded, requirejs knows pass module:

requirejs.config({     // ...     shim: {         'google': {             exports: 'google'         },     } }); 

in sample above saying when google module loads, pass global window.google variable module reference module.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -