Best way to execute Angular unit test

50 views Asked by At

I want to execute unit test in Angular with the help of spec.ts file of every component/service but even with reading some documents i don't know if i'm using the best way to do it.

I face some problems when i try to test a component or service with some Provider Injection in it (in the ts file not the spec) and i'm be forced to imports my AppModule inside my spec file to be able to execute my spec file ? am i doing a wrong when i inject provider inside my component/service ? or i didn't know how to imports what i need inside my spec file ?

here is my spec file :

describe('_myService', () => {
  beforeEach(() => TestBed.configureTestingModule({
    imports: [AppModule],
  }));

  it('should be created', () => {
    const service: MyService = TestBed.get(MyService);
    expect(service).toBeTruthy();
  });
}); 

and here is my service :

export class MyService implements IMyService  {

  constructor(
    @Inject(IAnotherServiceProvider) private _providerClass: IAnotherService,
  ) { }

}

i can put other class (IAnotherServiceProvider, IAnotherService and IMyService)

0

There are 0 answers