更新 Angular 9 到 10 后测试中断
tests broken after updating Angular 9 to 10
在我将 Angular 从 9 更新到 10 之后,我所有的笑话测试都被打破了。他们在更新之前工作得很好。
我该如何解决这个问题?
这是我的一项测试:
@Component({
selector: 'prof-notifications-form',
template: '',
})
describe('NotificationsFormComponent', () => {
let component: NotificationsFormComponent;
let fixture: ComponentFixture<NotificationsFormComponent>;
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [ReactiveFormsModule, MatDialogModule, UiButtonModule],
declarations: [NotificationsFormComponent ],
}).compileComponents();
})
);
beforeEach(() => {
fixture = TestBed.createComponent(NotificationsFormComponent);
component = fixture.componentInstance;
component.urlResolver = jest.fn(url => `http://someSampleUrl.test/${url}`);
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
这是抛出的错误:
Unexpected value 'CommonModule' imported by the module 'UiButtonModule'. Please add an @NgModule annotation.
我解决了:)
只需将节点从 12 升级到 14 即可正常运行!
在我将 Angular 从 9 更新到 10 之后,我所有的笑话测试都被打破了。他们在更新之前工作得很好。 我该如何解决这个问题?
这是我的一项测试:
@Component({
selector: 'prof-notifications-form',
template: '',
})
describe('NotificationsFormComponent', () => {
let component: NotificationsFormComponent;
let fixture: ComponentFixture<NotificationsFormComponent>;
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
imports: [ReactiveFormsModule, MatDialogModule, UiButtonModule],
declarations: [NotificationsFormComponent ],
}).compileComponents();
})
);
beforeEach(() => {
fixture = TestBed.createComponent(NotificationsFormComponent);
component = fixture.componentInstance;
component.urlResolver = jest.fn(url => `http://someSampleUrl.test/${url}`);
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
这是抛出的错误:
Unexpected value 'CommonModule' imported by the module 'UiButtonModule'. Please add an @NgModule annotation.
我解决了:) 只需将节点从 12 升级到 14 即可正常运行!