Closed bahmutov closed 4 years ago
The js transforms defined in webpack are applied to the script portion.
:tada: This issue has been resolved in version 3.4.4 :tada:
The release is available on:
npm package (@latest dist-tag)
Your semantic-release bot :package::rocket:
How to mock
axios
import from a Vue component?We can try importing axios module and mocking a method
The above fails, seems the imported modules are different objects. See PR #345 for code
Details
In other situations (and even in this library), I solve mocking ES6 imports by inserting a Babel plugin
@babel/plugin-transform-modules-commonjs
into the plugins list with these optionsIn "normal" JavaScript bundle this transform creates a shared object for every file
and thus mocking the
'./src/foo.js'.name
from the spec changes the value in every module that imports it too.Seems in our situation the
vue-loader
and JavaScript combination do NOT share these objects. Maybe the@babel/plugin-transform-modules-commonjs
is not applied to the JavaScript fragment aftervue-loader
loads it? Maybe therequire
cache is set up separately for the code from.vue
files vsnode_modules
file, I don't know. External help would be welcome.