Moh*_*sen 2 javascript integration-testing unit-testing jasmine angular
我正在 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);
});
});
});
Run Code Online (Sandbox Code Playgroud)
我收到以下错误,但我不知道我错在哪里。
error TS2304: Cannot find name 'createNewEvent'.
我已经使用了角度网站上的这种方法。
如果您尝试调用输入事件,则可以这样做:
input.dispatchEvent(new Event('input'));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
373 次 |
| 最近记录: |