错误 TS2304:找不到名称 'createNewEvent'

error TS2304: Cannot find name 'createNewEvent'

我正在为 Angular 11 中的输入框编写单元测试。

这是我的 spec.ts 代码:

import { ComponentFixture, TestBed } from '@angular/core/testing';
import 'jasmine';
import { ExpectedConditions } from 'protractor';
import { MicroplateComponent } from './microplate.component';

describe('MicroplateComponent', () => {
  let component: MicroplateComponent;
  let fixture: ComponentFixture<MicroplateComponent>;

  beforeEach(async () => {
    await TestBed.configureTestingModule({
      declarations: [MicroplateComponent]
    })
      .compileComponents();
  });

  beforeEach(() => {
    fixture = TestBed.createComponent(MicroplateComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  describe('Evaluation of input box', () => {
    it('Should return true for "1, 2, 3"', () => {
      const input = fixture.nativeElement.querySelector('input');
      const event = createNewEvent('input'); // I get error at this line

      input.value = '1, 2, 3';
      input.dispatchEvent(event);

      fixture.detectChanges();

      expect(component.columns?.valid).toBe(true);
    });
  });
});

我得到以下错误,但我不知道我哪里错了。

error TS2304: Cannot find name 'createNewEvent'.

我使用了 angular 网站上的这种方法。

如果您尝试调用输入事件,您可以这样做:

input.dispatchEvent(new Event('input'));