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


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -