问题描述
我正在尝试使用nestjs为基于单仓库的应用程序编写单元测试用例。
我遇到以下错误
nest cannot export a provider/module that is not a part of the currently processed module (CacheManagerModule). Please verify whether the exported CACHE_MANAGER_REPOSITORY is available in this particular context.
Possible Solutions:
- Is CACHE_MANAGER_REPOSITORY part of the relevant providers/imports within CacheManagerModule?
使用的软件包如下
"@nestjs/testing": "6.11.7","jest": "25.1.0","ts-jest": "25.0.0"
请参考下面的示例代码
apps \ api \ src \ modules \ enduse \ enduse.controller.spec.ts
import { InestApplication } from "@nestjs/common";
import { Test } from "@nestjs/testing";
import { CacheManagerModule } from "@app/cache-manager";
import * as request from "supertest";
import { EnduseController } from "./enduse.controller";
import { EnduseService } from "./enduse.service";
describe("Enduse",() => {
let app: InestApplication;
beforeAll(async () => {
const module = await Test.createTestingModule({
imports: [CacheManagerModule],controllers: [EnduseController],providers: [EnduseService],}).compile();
app = module.createnestApplication();
await app.init();
});
it("/ (Get Enduse)",async () => {
const response = await request(app.getHttpServer()).get("enduse/mapping?enduse=123").expect(200);
return response;
});
});
libs \ cache-manager \ src \ cache-manager.module.ts
import { Module } from "@nestjs/common";
import { CacheManagerService } from "./cache-manager.service";
import { CacheManagerProviders } from "./cache-manager.provider";
@Module({
providers: [CacheManagerService,...CacheManagerProviders],exports: [CacheManagerService,})
export class CacheManagerModule {}
libs \ cache-manager \ src \ cache-manager.provider.ts
import { Reviewmodel } from "@app/database/models";
import { CACHEMANAGERCONST } from "./cache-manager.const";
export const CacheManagerProviders = [
{
provide: CACHEMANAGERCONST.CACHE_MANAGER_REPOSITORY,useValue: Reviewmodel,},];
jest.config.js
moduleNameMapper: {
"^@app/cache-manager": resolve(__dirname,"./libs/cache-manager/src")
}
如何解决该问题?
谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)