Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5049

Testing Component or Sevice containing "declare var" with Jest

$
0
0

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...

//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, HttpClient],
    }).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();
});

Viewing all articles
Browse latest Browse all 5049

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>