vue-pdf-embed Inline worker is not supported on jest



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

问题是当我运行jest。

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变量中,但没有成功

我得到了一个合理的答案:模拟组件:

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

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

现在一切正常;)

相关内容

最新更新