How to mock environment files import in unit tests

前端 未结 3 1354
花落未央
花落未央 2021-02-19 13:11

In our angular app, we use environment files to load some config.

environment.ts

export const environment = {
  production: false,
  defaultLocale: \'en         


        
3条回答
  •  甜味超标
    2021-02-19 13:34

    A technique I use in situations like this is to create a wrapper service e.g. EnvironmentService.ts and in this case it returns the environment configuration.

    This allows me to mock calls to the EnvironmentService's getEnvironmentConfiguration method just like any other spyOn call.

    This then allows for the modification of environment variables in unit tests :)

提交回复
热议问题