I am writing a Unit Test for my input box in Angular 11.
Here is my spec.ts code:
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);
});
});
});
I get the following error, but I don't know where I am wrong.
error TS2304: Cannot find name 'createNewEvent'.
I have used such an approach from angular website.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…