Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

jasmine - From Angular autogenerated spec tests toward best practises

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);
    });
question from:https://stackoverflow.com/questions/65834816/from-angular-autogenerated-spec-tests-toward-best-practises

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...