I have a Vue project which was created using Vue CLI v3.5 and am trying to write some component unit tests. I have jquery as a webpack external in vue.config.js as follows:
...
configureWebpack: {
externals: {
jquery: 'jQuery'
}
}
...
and I load jquery from a CDN in a script tag in index.html. Obviously whenever I run vue-cli-service test:unit
I get the following error since jquery isn't a dependency in the project:
RUNTIME EXCEPTION Exception occurred while loading your tests
ReferenceError: jQuery is not defined
at Object.jquery (.../public/webpack:/external "jQuery":1:1)
...
I realize in my unit tests I should probably mock jquery somewhere, but I'm not sure what's the correct way to do this so I only do it in one place within the testing config.