【发布时间】:2022-01-12 18:20:29
【问题描述】:
我在upgrading Swiper 6 to 7 之后的单元测试中遇到了问题。我正在使用 Angular 12 和 Swiper 7.3.1。在升级之前,单元测试运行良好(Swiper 版本 6.5.9)。
我在这样的测试中使用SwiperModule:
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { of } from 'rxjs';
import { SwiperComponent, SwiperModule } from 'swiper/angular';
import { TeaserWrapperContainerComponent } from './teaser-wrapper-container.component';
import { InterfaceState } from '@migrosonline/shared-deps-all/core/interface/interface.store';
describe('TeaserWrapperContainerComponent', () => {
let component: TeaserWrapperContainerComponent;
let fixture: ComponentFixture<TeaserWrapperContainerComponent>;
const mockedSwiperComponent = {
swiperRef: {
slideNext: jest.fn(),
slidePrev: jest.fn(),
destroy: jest.fn(),
update: jest.fn()
}
} as unknown as SwiperComponent;
beforeEach(
waitForAsync(() => {
mockedInterfaceService.prototype.select = jest.fn();
TestBed.configureTestingModule({
declarations: [TeaserWrapperContainerComponent],
imports: [SwiperModule],
providers: [{ provide: InterfaceService, useClass: mockedInterfaceService }],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
}).compileComponents();
})
);
beforeEach(() => {
fixture = TestBed.createComponent(TeaserWrapperContainerComponent);
component = fixture.componentInstance;
component.teaserGroupSliderRef = mockedSwiperComponent;
});
it('should create', () => {
fixture.detectChanges();
expect(component).toBeTruthy();
});
});
我得到的错误是这样的:
Cannot find module 'swiper_angular' from 'src/lib/shared/teaser/teaser-wrapper-container/teaser-wrapper-container.component.spec.ts'
3 | import { of } from 'rxjs';
> 4 | import { SwiperComponent, SwiperModule } from 'swiper/angular';
如果有任何想法/cmets/建议,我将不胜感激。
【问题讨论】: