Issue
I'm running into a problem on my unit tests after upgrading Swiper 6 to 7. I'm using Angular 12 and Swiper 7.3.1. Before upgrading it the unit tests were working fine (Swiper version 6.5.9).
I'm using the SwiperModule in my tests like this:
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();
});
});
and the error I get is this one:
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';
I would appreciate any ideas/comments/suggestions.
Solution
In case someone else run into this issue, the problem was related to the eslint or tslint configuration for the test and it got fixed adding the swiper_angular to the compilerOptions > paths in the tsconfig.json (or the tsconfig.spec.json) file:
"compilerOptions": {
...
"paths": {
"swiper_angular": ["node_modules/swiper/angular"]
}
}
I found the solution in the Swiper issues: https://github.com/nolimits4web/swiper/issues/4315
Answered By - vhbazan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.