我有以下模块
declare module 'environment' {
// eslint-disable-next-line import/no-unresolved
import baseEnv from './environments/base';
const value: ReturnType<typeof baseEnv>;
export default value;
}
environment.base。 =返回环境对象
...
...
export type Environment = ReturnType<typeof baseEnv>;
然后在服务文件中,我像
一样导入它import environment from 'environment';
import { EnvironmentInterface } from '../../environments/base';
我的问题是如何进行测试
如果有帮助,我会将其导入Inversify.js服务中 像这样的服务:
import { injectable } from 'inversify';
import environment from 'environment';
import { EnvironmentInterface } from '../../environments/base';
import { IConfig } from './config.interface';
@injectable()
export class ConfigService implements IConfig {
public config: EnvironmentInterface;
constructor() {
this.config = environment;
}
get(): EnvironmentInterface {
return this.config;
}
}
我尝试使用
jest.spyOn('environment'),但我知道此模块未定义
所以当我想测试使用此配置服务的服务时,会遇到此问题
例如,当我尝试将env移到反文件并在构造函数中使用它但仍然得到它时,此结果
Cannot find module 'environment' from 'inversify.config.ts'
1 | import 'reflect-metadata';
2 | import { Container } from 'inversify';
> 3 | import enviornment from 'environment';
| ^
4 | import { ConfigService, IConfig } fro