Angular13+jest+Angularlibrarynotworking
创始人
2024-10-21 22:30:03
0

在 Angular 13 中,有一些问题可能会导致 Jest 无法正确使用 Angular 库。需要按照以下步骤来解决该问题:

  1. 确保在 tsconfig.spec.json 文件中正确配置 libtypes
{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/spec",
    "baseUrl": "./",
    "types": [
      "jest",
      "node"
    ],
    "lib": [
      "dom",
      "es2020"
    ]
  },
  "exclude": [
    "node_modules"
  ]
}
  1. polyfills.ts 文件中添加以下导入语句和函数。
import 'zone.js/testing';
export function getTestBed() {
    return TestBed as any;
}
  1. jest.config.js 文件中添加以下设置。
module.exports = {
  ...
  globals: {
    'ts-jest': {
      tsconfig: '/tsconfig.spec.json',
      stringifyContentPathRegex: '\\.html$',
      astTransformers: {
        before: [
          'jest-preset-angular/build/InlineFilesTransformer',
          'jest-preset-angular/build/StripStylesTransformer'
        ]
      }
    }
  },
  ...
};

通过以上步骤处理后,Angular 库将能够正常与 Jest 集成。

相关内容

热门资讯

透视妙招!wepoker可以开... 透视妙招!wepoker可以开透视吗(WePoKer规律)真是是有辅助插件(哔哩哔哩)1、透视妙招!...
透视练习!wepoker黑侠辅... 透视练习!wepoker黑侠辅助器(WePoKer开辅助)好像真的是有辅助教程(哔哩哔哩)1、透视练...
透视法门!pokemmo修改器... 透视法门!pokemmo修改器手机版(德普之星官网)原来真的是有辅助神器(哔哩哔哩)1、首先打开po...
透视指南!hhpoker透视脚... 透视指南!hhpoker透视脚本视频(HHpoker必备)总是有辅助软件(哔哩哔哩)在进入hhpok...
透视操作!wepoker辅助器... 透视操作!wepoker辅助器软件下载(AApoker辅助)确实真的有辅助神器(哔哩哔哩)1、wep...
透视大纲!有哪些免费的wpk作... 透视大纲!有哪些免费的wpk作必弊码(HHpoker必备)确实是有辅助神器(哔哩哔哩)1、用户打开应...
透视窍要!epoker透视底牌... 透视窍要!epoker透视底牌(HHpoker安装包)其实真的是有辅助插件(哔哩哔哩)1、epoke...
透视妙计!wepoker透视脚... 透视妙计!wepoker透视脚本是什么(HHpoker德州)本来真的是有辅助app(哔哩哔哩)1、点...
透视妙计!we poker辅助... 透视妙计!we poker辅助器下载(WePoKer数据)果然真的有辅助脚本(哔哩哔哩)1、打开软件...
透视窍门!wpk俱乐部辅助器(... 透视窍门!wpk俱乐部辅助器(HHpoker教程)真是是真的有辅助app(哔哩哔哩)小薇(辅助器软件...