简体   繁体   中英

how to write custom .spec.ts file in a angular application

I want to make a custom .spec.ts file in my angular application which can test all the methods of components.ts files and service.ts file & i want to test the non-value returning methods also.

I created a custom spec.ts file for testing my application, but those test are failed

it('should handle', () => { 
    expect(component.Id).toBe(null);
    component.isKeyUp();
    expect(component.show).toBe(true);
  });

It is showing Id not found in my custom.spec.ts file ,but in that component.spec.ts file it run perfectly.

You need to call detectChanges() method in component after isKeyUp() has been invoked.

it('should handle', () => { 
    expect(component.Id).toBe(null);
    component.isKeyUp();
    component.detectChanges();
    expect(component.show).toBe(true);
  });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM