【发布时间】:2021-03-01 19:29:25
【问题描述】:
在我将 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.
【问题讨论】:
-
你能显示 UiButtonModule 吗?如果它是一个模块,它应该在导入下,而不是声明下。 Angular 10 比以前做了更多的类型检查。
-
谢谢博扬,但它只是给了我另一个错误,我已经相应地更新了代码和错误消息。是的,UiButtonModule 是一个模块
-
你修复了你原来的错误。我认为您可能在 UiButtonModule 中有一个错误,您也可以展示一下吗?确保 CommonModule 在导入中
标签: angular testing jestjs angular10