Test angular 4 app with a global variable -
i have angular app using global variable set external .js library within ngoninit(). building , running works without issue. when running test (with karma) error "myglobal not defined". i tried defining variable before describe(), this: var myglobal = { }; describe('appcomponent', () => { that doesn't change anything. how supposed define variable ? to solve you'll need access window object using windowref component import {windowref} './windowref'; and in class constructor(private winref: windowref) { console.log('window object', winref.nativewindow['yourglobalvar']); //or winref.nativewindow.yourglobalvar } source here