Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

198
Views
moke the typeORM repository for testing with jest in the express/koa

Estoy llamando a métodos de repository dentro del service y ahora tengo que escribir la prueba unitaria para el servicio. Quiero moke Repository Class o Method ambos.

Aquí está el código de service para el que tengo que escribir una prueba.

 import { AttackMatrixRepo } from '../repositories/index'; export const serGetAttackMatrixDetail = async () => { const attMatRepo = new AttackMatrixRepo(); const table = await attMatRepo.repGetMatric(); return table; };

Aquí está el código del repositorio.

 import { AttackMatrix } from '../entities/index'; // typeorm AttackMatrix schema import { Repository, BaseEntity } from 'typeorm'; import { AppDataSource } from '../bootstrap/typeorm'; // typeorm connection export class AttackMatrixRepo extends BaseEntity { private attackMatrixEntity: Repository<AttackMatrix>; constructor() { super(); this.attackMatrixEntity = AppDataSource.getRepository(AttackMatrix); } public async repGetMatric() { return this.attackMatrixEntity.createQueryBuilder('attMatric').getOne(); } public async getMatrixByStixId({ columNames = ['*'], stixId }): Promise<AttackMatrix> { const tacticQueryBuilder = await this.attackMatrixEntity.createQueryBuilder('matrix'); const query = tacticQueryBuilder.select(columNames).where('matrix.stix_id = :stixId', { stixId }); return query.getRawOne(); } }

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!