Angular provides some auto-generated spec files.
Let's assume we have following test:
describe('BlebleAddComponent', () => {
let component: BlebleAddComponent;
let fixture: ComponentFixture<BlebleAddComponent>; beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [BlebleAddComponent],
schemas: [NO_ERRORS_SCHEMA],
imports: [
RouterTestingModule.withRoutes([
{path: 'test', component: BlebleAddComponent}
])
],
providers: [
FormBuilder,
{provide: BlebleService, useValue: jasmine.createSpyObj([''])}, ]
})
.compileComponents();
})); beforeEach(() => {
fixture = TestBed.createComponent(BlebleAddComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
Does this test bring any value with only toBeTruthy used?
expect(component).toBeTruthy();
I am not angular developer but I assume that above test provides only little if any value.
It might become valuable when:
- it contains some clear test description - then would serve as requirements specification/documentation
- it supports BDD given-when-then approach, so it should be enriched with some assertions that checks expectations e.g.:
describe('bleble registration', () => {
...
it('Valid BleBle should be registered', () => {
//Given
bleble = ...
//when
response = service.register(bleble)
expect(response).equals(200);
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…