samedi 7 décembre 2019

Testing Component or Sevice containing "declare var" with Jest

While testing my component or service I getting the error

ReferenceError: flagPath is not defined

flagPath is coming from a config.js file in the assets folder. is there a way to add it to the TestBed?? I am using jest and I am not sure where to add it. I have read that in karma you can just add it to the Var files... HELP!!

 //imports...
   declare var flagPath: string;

  @Injectable({
      providedIn: 'root'
    })
    export class Service {
    constructor(private http: HttpClient) {}

      getMaxContent(): Observable<any> {
        return this.http.get(flagPath);
      }

In my test all doing is testing truthy see below:

let service: Service;

   beforeEach(async(() => {
    TestBed.configureTestingModule({
      schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
      declarations: [
        OverviewComponent,
      ],
      imports: [],
      providers: [Service],
    }).compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(OverviewComponent);
    service = fixture.debugElement.injector.get(Service);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', async () => {
    component.ngOnInit();
    fixture.whenStable();
    expect(component).toBeTruthy();
  });

Thank you

Aucun commentaire:

Enregistrer un commentaire