Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k 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);
    });

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

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...