小编Hel*_*hin的帖子

如何在Angular 7(或2+)中编写文件上传方法的单元测试

我正在尝试为 angular 7 中的文件上传方法编写单元测试。在测试窗口中出现以下错误。我是角度单元测试的新手。有人可以帮忙,如何添加模拟文件以获得完整的代码覆盖率?

类型错误:无法设置未定义的属性“值”

这是我的单元测试代码(规范文件),

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

    beforeEach(
        async(() => {
            TestBed.configureTestingModule({
                imports: [ HttpClientModule, RouterTestingModule ],
                declarations: [ ImportComponent ]
            }).compileComponents();
        })
    );

    beforeEach(() => {
        fixture = TestBed.createComponent(ImportComponent);
        component = fixture.componentInstance;
        element = fixture.nativeElement;
        fixture.detectChanges();
    });

    it('should create', () => {
        expect(component).toBeTruthy();
    });

    it('should upload the file', () => {
        component.importFile();
        const inputEl = element.querySelector('#postal_file');
        const fileList = { 0: { name: 'foo', size: 500001 } }; …
Run Code Online (Sandbox Code Playgroud)

karma-jasmine angular angular-test

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

angular ×1

angular-test ×1

karma-jasmine ×1