我想学习如何使用业力茉莉花创建角2(打字稿文件)的测试。我怀疑,要测试component.ts文件,我只能测试我在HTML文件中调用的方法,或者我可以测试所有这些方法吗? 例如:我有这个模型文件modal.nota.component.ts角2测试业力。什么测试
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { Nota } from './nota.model'
@Component({
moduleId: module.id,
selector: 'modal-nota',
templateUrl: 'modal.nota.component.html'
})
export class ModalNotaComponent {
test : boolean = true;
setFalse(test) {
this.test = false;
return test;
}
}
而且我不调用该方法“setFalse”在我的HTML文件,但我想试探他。我如何在我的spec文件中调用和测试该方法? modal.nota.spec.ts
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { ModalNotaComponent } from '../modal.nota.component';
describe('Test of test variable',() => {
let component: ModalNotaComponent;
let fixture: ComponentFixture<ModalNotaComponent>;
beforeEach(() => {
TestBed.compileComponents(); // ModalNotaComponent test instance
TestBed.configureTestingModule({
declarations: [ ModalNotaComponent ], // declare the test component
});
fixture = TestBed.createComponent(ModalNotaComponent);
component = fixture.componentInstance;
});
it('Should show that the value of test variable is true',() => {
expect(component.test).toBe(true);
});
it('Should test setFalse method',() => {
let r = null;
let t = true;
r = component.setFalse(t);
expect(r).toBe(false);
});
});
这个测试是行不通的。我得到这个错误 photo of the errors
谢谢。你的答案有助于解决一些错误,但不是全部,但我很感激。 –