I have a config attached to the window object in /public/js/settings.js file:
window.mySettings = {
foo: 1,
bar: 2,
}
I import these settings in a vuex store file baz.storage.js in a vue project:
import settings from 'mySettings';
It all works except that jest doesn't understand this export:
Cannot find module 'mySettings' from 'baz.storage.js'
And so the whole jest suite fails.
If
/js/settings.jsis included in your page, you don't need import it in the baz.storage.js but make suresettings.jsis include at first.Eg:
settings.jsis added at first in the above example so thatwindow.mySettingswill be available for thescript2.jsandscript3.jsonce you declared a variable in the
windowit is declared at the global scope and it can be accessed from all the other scripts.Eg: