SuperAPI AI 工具集

angular-jest

前端与建站

查看项目

更新于 10-16 02:35

技能介绍

用途:在 Angular 应用中使用 Jest 做单元测试,包括配置 Jest,以及从 Jasmine/Karma 迁移到 Jest。

主要能力:提供 Jest 29.x(2025)与 jest-preset-angular 的集成实践,覆盖安装、配置和测试编写。

安装:npm install --save-dev jest @types/jest jest-preset-angular

配置:在 jest.config.js 中使用 preset: 'jest-preset-angular',通过 setupFilesAfterEnv 指向 setup-jest.ts,并用 testPathIgnorePatterns 忽略 node_modules。

编写测试:从 @angular/core/testing 引入 ComponentFixture、TestBed,在 beforeEach 中调用 TestBed.configureTestingModule 并 compileComponents,再通过 TestBed.createComponent 创建组件实例,使用 expect 断言。

适用场景:Angular 组件与单元测试、Jest 配置、Jasmine/Karma 迁移。

限制:资料未提供迁移的具体步骤、版本兼容细节、性能或收费信息。