我正试图为一个使用FullCalendar for Angular的组件创建一个单元测试。知道如何解决这个问题吗?
Details:
...........node_modules@fullcalendarcoremain.js:6
import './vdom';
^^^^^^
SyntaxError: Cannot use import statement outside a module
1 | import {async, ComponentFixture, TestBed} from "@angular/core/testing";
> 2 | import {FullCalendarModule} from "@fullcalendar/angular";
| ^
3 | import dayGridPlugin from "@fullcalendar/daygrid";
4 | import interactionPlugin from "@fullcalendar/interaction";
5 | import {CalendarComponent} from "../../calendar/calendar.component";
at Runtime._execModule (../node_modules/jest-runtime/build/index.js:1179:56)
at ../node_modules/@fullcalendar/angular/bundles/fullcalendar-angular.umd.js:2:139
at Object.<anonymous> (../node_modules/@fullcalendar/angular/bundles/fullcalendar-angular.umd.js:5:2)
at Object.<anonymous> (app/private-pages/booking/booking-page.component.spec.ts:2:1)
希望这对那些过去解决过这个问题的人来说是足够的信息。如果您需要更多信息(例如完整的代码等(,请告诉我
我发现这个SO答案对我的情况没有帮助(很可能它针对的是React,而不是Angular(:自定义cra为JEST 编译node_modules
在测试文件中,您需要模拟完整的日历,如下所示:
jest.mock('@fullcalendar/angular', () => () => <div />);