Angular Unit Test 单元测试01
-
完成一个测试用例最基础的4个概念:
// 测试细则套件
describe(description: string, specDefinitions: () => void): void;
// 预处理函数
beforeEach(() => {})
// 定义细则,包含若干测试预期
it (‘specDesc, fn’)
// 预期
expect(val1).toBe(val2);
describe('NgBindingComponent', () => { // 测试细则套件
let component: NgBindingComponent;
let fixture: ComponentFixture<NgBindingComponent>;
beforeEach(async () => { // 预处理函数-异步
await TestBed.configureTestingModule({
declarations: [ NgBindingComponent ]
})
.compileComponents();
});
beforeEach(() => { // 预处理函数
fixture = TestBed.createComponent(NgBindingComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => { // case 1 定义细则,包含若干测试预期
expect(component).toBeTruthy(); // case 1 预期
});
it('routerInfo is empty', () =>{ // case 2 定义细则,包含若干测试预期
expect(component.routerInfo).toBe(''); //case 2 预期
})
});