Mocha无法在我的configService类上传递getter函数的值,我不知道为什么。有人知道我需要改变什么吗?
这是我的摩卡测试的样本代码:
const path = require('path');
const dotEnvPath = path.resolve('./.env');
require('dotenv').config({ path: dotEnvPath});
import { configService } from '../path';
import { ExampleService } from '../path';
it("should do this test", async function() {
await configService.init()
await ExampleService.makeHappen();
});
这是我的配置类示例:
console.log(networkNode)
显示正确读取右侧
ENV
参数
let network = '';
class ConfigService {
async init() {
network = process.env.NETWORK_NODE
}
get network() {
return network;
}
}
这是另一个使用get函数的类。
console.log(NETWORK)
async函数内部显示一个空白,这意味着没有从get函数中检索到任何内容
import { configService } from '../path';
const NETWORK = configService.network;
class ExampleService {
async makeHappen() {
if (NETWORK == statement) {
// do this
} else {
// else do this
}
}
}