我将在 Angular 12 下使用 Storybook 安装快照测试。我安装 jest$ yarn add --dev jest jest-preset-angular @types/jest
并进行设置
"jest": {
"preset": "jest-preset-angular",
"setupFilesAfterEnv": ["<rootDir>/src/setupJest.ts"]
}
并设置 setupJest.ts 数据只有一行import 'jest-preset-angular/setup-jest';
。
那是开玩笑的设置。这对我有用。
问题是来自 Storybook 的 Storyshorts 插件。我安装 Storyshorts并使用以下代码yarn add @storybook/addon-storyshots --dev
创建文件:src/storyshorts.test.js
import initStoryshots from '@storybook/addon-storyshots';
initStoryshots();
jest
当我在我的 Angular 项目中运行命令时,我变成了这个错误:
Cannot find module 'jest-preset-angular/build/setup-jest' from 'node_modules/@storybook/addon-storyshots/dist/ts3.9/frameworks/angular/loader.js'
at Resolver.resolveModule (node_modules/jest-resolve/build/resolver.js:324:11)
at setupAngularJestPreset (node_modules/@storybook/addon-storyshots/dist/ts3.9/frameworks/angular/loader.js:36:14)
at Object.load (node_modules/@storybook/addon-storyshots/dist/ts3.9/frameworks/angular/loader.js:43:5)
at Object.loadFramework [as default] (node_modules/@storybook/addon-storyshots/dist/ts3.9/frameworks/frameworkLoader.js:26:19)
at Object.testStorySnapshots [as default] (node_modules/@storybook/addon-storyshots/dist/ts3.9/api/index.js:42:39)
我的 Package.json 有以下条目:
...
"@storybook/addon-storyshots": "^6.3.12",
"@types/jest": "^27.0.2",
"jest": "^27.3.1",
"jest-preset-angular": "^10.0.1",
和 Angular 12 包。