我正在对项目添加测试并提高覆盖范围。我想知道如何在 NestJs 中测试模块定义(mymodule.module.ts 文件)。特别是,我正在测试一个导入其他模块的主模块,其中一个模块初始化数据库连接,这意味着我需要模拟另一个模块上的服务,以避免真正的数据库连接。此时此刻我有这样的事情:
beforeEach(async () => {
const instance: express.Application = express();
module = await NestFactory.create(MyModule, instance);
});
describe('module bootstrap', () => {
it('should initialize entities successfully', async () => {
controller = module.get(MyController);
...
expect(controller instanceof MyController).toBeTruthy();
});
});
Run Code Online (Sandbox Code Playgroud)
这可行,但我相信这可以得到改进:)
理想的情况是 Test.createTestingModule 提供的 overrideComponent 方法。
PS:我使用的是4.5.2版本
我正在开发一个包含20多个活动的应用程序,我的strings.xml的大小正在增长.我怀疑哪个是最佳选择,为整个应用程序使用单个文件或创建链接到具有共同内容的活动集的不同strings.xml ...
你说什么?
谢谢