【问题标题】:vue-pdf-embed Inline worker is not supported on jestjest 不支持 vue-pdf-embed Inline worker
【发布时间】:2023-01-31 20:54:23
【问题描述】:

我正在使用 Vue 3 + Jest 28。
我决定试试vue-pdf-embed,效果很好。

问题是当我开玩笑时。

它说

  Inline worker is not supported

有了这个我无法继续并陷入困境。

我的jest.config.ts 看起来像这样:

const esModules = ['quasar', 'quasar/lang', 'lodash-es', 'cnpj'].join('|');

module.exports = {
  verbose: true,
  testEnvironment: 'jsdom',
  testEnvironmentOptions: {
    url: 'http://localhost/',
    customExportConditions: ['node', 'node-addons'],
  },
  globals: {
    'ts-jest': {
      tsconfig: '<rootDir>/tests/tsconfig.json',
      isolatedModules: true,
    },
  },
  collectCoverageFrom: ['src/**/*.{vue,js,ts}', '!src/*.{js,ts}', '!**/typings/**', '!src/**/definitions/*.ts'],
  coverageProvider: 'v8',
  setupFiles: [
    '<rootDir>/tests/jest.init.ts',
  ],
  setupFilesAfterEnv: ['<rootDir>/tests/setupTests.ts'],
  moduleFileExtensions: [
    'vue',
    'js',
    'ts',
    'json',
    'jsx',
    'tsx',
  ],

  transform: {
    // See https://jestjs.io/docs/en/configuration.html#transformignorepatterns-array-string
    [`^(${esModules}).+\\.js$`]: 'babel-jest',
    '^.+\\.(ts|js|html)$': 'ts-jest',
    // vue-jest uses find-babel-file, which searches by this order:
    //  (async) .babelrc, .babelrc.js, package.json, babel.config.js
    //  (sync) .babelrc, .babelrc.js, babel.config.js, package.json
    // https://github.com/tleunen/find-babel-config/issues/33
    '.*\\.vue$': '@vue/vue3-jest',
    '.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$':
      'jest-transform-stub',
  },

  transformIgnorePatterns: [`node_modules/(?!(${esModules}))`],

  moduleNameMapper: {
    '@/(.*)$': '<rootDir>/src/$1',
    '^quasar$': 'quasar/dist/quasar.esm.prod.js',
    'lodash-es': 'lodash',
  },

  snapshotSerializers: ['<rootDir>/node_modules/jest-serializer-vue'],
};

到目前为止,我已经尝试将它添加到我的 jest 配置中的 esModules 变量中,但没有成功

【问题讨论】:

    标签: vue.js jestjs


    【解决方案1】:

    我给出了一个合理的答案:模拟组件:

    在我在上面的jest.config.ts 中提到的jest.init.ts 中,我输入了以下内容:

    jest.mock('vue-pdf-embed', () => () => '<mock-vue-pdf-embed/>');
    

    现在一切正常;)

    【讨论】:

      【解决方案2】:

      谢谢你。您提供的解决方案工作正常。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-16
        • 2014-05-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多