我正在尝试模拟我的服务的 findAll 功能。为此,我需要模拟存储库函数findAndCountmyEntityRepository 或paginateNestjs-typeorm-paginate 节点模块的函数。findAll函数从表中获取记录列表,并使用 NodeModule Nestjs-typeorm-paginate进行分页。
Try-1:模拟 myEntityRepository 但它失败并出现错误和回溯:
TypeError: queryBuilder.limit is not a function
at ../node_modules/nestjs-typeorm-paginate/dist/paginate.js:119:28
at ../node_modules/nestjs-typeorm-paginate/dist/paginate.js:8:71
at Object.<anonymous>.__awaiter (../node_modules/nestjs-typeorm-paginate/dist/paginate.js:4:12)
at paginateQueryBuilder (../node_modules/nestjs-typeorm-paginate/dist/paginate.js:115:12)
at Object.<anonymous> (../node_modules/nestjs-typeorm-paginate/dist/paginate.js:22:15)
at ../node_modules/nestjs-typeorm-paginate/dist/paginate.js:8:71
Run Code Online (Sandbox Code Playgroud)
我的服务.ts
import { IPaginationOptions, paginate, Pagination } from 'nestjs-typeorm-paginate'
export class MyService {
constructor(@InjectRepository(MyEntity) private myEntityRepository: Repository<MyEntity>) { }
async findAll(options: IPaginationOptions): Promise<Pagination<MyEntity>> {
try {
return await paginate<MyEntity>(this.myEntityRepository, options)
} catch (error) {
throw error
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的服务规格
describe('MyService …Run Code Online (Sandbox Code Playgroud)