[Vuejs]-Jest testing Vue Single File Components with Ionic Capacitor plugin imports

0👍

Per @jcesarmobile’s comment on the OP, updating @capacitor/core from version 1.0.0 to 1.1.0 resolved the issue entirely.

Fix: make capacitor compatible with commonjs

0👍

EDIT

Although this made the test past, upgrading the @capacitor/core package to v1.1.0 (released just hours ago) resolved the issue, too.


Following the Jest docs on mocking Node modules – specifically scoped modules – I created a __mocks__ folder under root, created a directory underneath it named @capacitor and created a file underneath that called core.js. So I ended up with a structure like:

.
├─__mocks__
│ └─ @capacitor
│    └─ core.js

Inside of core.js I export the pieces that are imported by the Vue components I’m testing (currently only Plugins and Plugins.Filesystem):

// core.js
module.exports = {
  Plugins: {
    Filesystem: {}
  }
}

With those in place the Jest test passes with flying green colors.

Leave a comment