0

I have created a class in Angular 7 to load a config file for environment variables. This is using the accepted answer here Angular5: Deploying Angular application to multiple clients

Now I want to add unit testing to my Services but I get the following error:

TypeError: Cannot read property 'apiURL' of undefined

In other words when appConfig is imported, it is not recognised.

How can I stub the variable below to solve the error? I've tried using spy's but cannot get it working:

/**
 * Global variable containing actual config to use. Initialised via ajax call
 */
export let appConfig: AppConfig;
2
  • appConfig = { ... }? Commented May 3, 2019 at 7:07
  • But you should really really use dependency injection instead of using global variables. Commented May 3, 2019 at 7:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.