我尝试将 Jest 与 Spectator 一起使用来测试我的 Ionic 应用程序,但它在每次测试中都需要“@angular/animations”。
下面是一个简单的例子:
import { Spectator, createComponentFactory } from '@ngneat/spectator';
import { IonicModule } from '@ionic/angular';
import { NotificationsComponent } from './notifications.component';
describe('NotificationsComponent', () => {
let spectator: Spectator<NotificationsComponent>;
const createComponent = createComponentFactory({
component: NotificationsComponent,
imports: [IonicModule],
});
beforeEach(() => (spectator = createComponent()));
it('should create', () => {
expect(spectator).toBeTruthy();
});
});
运行该测试时出现此错误:
jest src/app/components/notifications/notifications.component.spec.ts
FAIL src/app/components/notifications/notifications.component.spec.ts
● Test suite failed to run
Cannot find module '@angular/animations' from 'node_modules/@angular/platform-browser/bundles/platform-browser-animations.umd.js'
Require stack:
node_modules/@angular/platform-browser/bundles/platform-browser-animations.umd.js
node_modules/@ngneat/spectator/bundles/ngneat-spectator.umd.js
setupJest.ts
at Resolver.resolveModule (../../../../usr/local/lib/node_modules/jest/node_modules/jest-resolve/build/resolver.js:313:11)
at node_modules/@angular/platform-browser/bundles/platform-browser-animations.umd.js:8:149
at Object.<anonymous> (node_modules/@angular/platform-browser/bundles/platform-browser-animations.umd.js:11:2)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 2.433 s
Ran all test suites matching /src\/app\/components\/notifications\/notifications.component.spec.ts/i.
我想知道如何在 Ionic 中使用 Jest/Spectator,谢谢!