【问题标题】:tests broken after updating Angular 9 to 10将 Angular 9 更新到 10 后测试中断
【发布时间】: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


【解决方案1】:

我解决了 :) 只需将节点从 12 升级到 14 即可使其正常工作!

【讨论】:

    猜你喜欢
    • 2021-01-02
    • 2020-12-29
    • 1970-01-01
    • 2020-12-13
    • 2022-06-30
    • 1970-01-01
    • 2020-06-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多