Wagmi and Web3Wallet for vue throws SyntaxError: Cannot use import statement outside a module in jest

96 views Asked by At

I'm using @wagmi/core and @web3modal/wagmi/vue in my Vue project. It works well, however, when I'm running unit tests, I'm getting

SyntaxError: Cannot use import statement outside a module

I've tried to change transformIgnorePatterns in my jest.config.js, but it didn't give any results. I'm using jest v.29.6.2, here is my jest.config.js content:

module.exports = {
  preset: 'ts-jest/presets/js-with-babel',
  testEnvironment: 'jsdom',
  testEnvironmentOptions: {
    customExportConditions: ['node', 'node-addons'],
  },
  coverageThreshold: {
    global: {
      branches: 55,
      functions: 64,
      lines: 70,
      statements: 70,
    },
  },
  testPathIgnorePatterns: ['/.deploy', '/build'],
  transformIgnorePatterns: ['<rootDir>/node_modules/(?!@wagmi/core| @web3modal/wagmi/vue)'],
  transform: {
    '^.+\\.vue$': '@vue/vue3-jest',
    '^.+\\.ts$': 'ts-jest',
    '^.+\\.js$': 'babel-jest',
    '.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$': 'jest-transform-stub',
    '^.+\\.svg$': '<rootDir>/tests/unit/svgTransform.js',
  },
  testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(js|ts)$',
  moduleNameMapper: {
    '^@/(.*)$': '<rootDir>/src/$1',
    '^.+/(.*\\.svg)': '<rootDir>/src/assets/images/$1',
    'moment/dist/locale/(.*)': 'moment/locale/$1',
  },
  moduleFileExtensions: ['vue', 'js', 'ts', 'json', 'scss', 'svg'],
  setupFiles: ['./jest.polyfills.js'],
  setupFilesAfterEnv: ['<rootDir>/tests/unit/jest_setup.ts'],
};

Thank you for your help in advance.

0

There are 0 answers