Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

203
Vistas
hot to moke the typeORM repositery for tesing with jest in the express/koa

I am calling repository methods inside of the service and now I have to write the unit test for the service. I want to moke repositery Class or Method both.

Here is the service code for which I have to write a test.

import { AttackMatrixRepo } from '../repositories/index';

export const serGetAttackMatrixDetail = async () => {
  const attMatRepo = new AttackMatrixRepo();
  const table = await attMatRepo.repGetMatric();
  return table;
};

Here is the repository code

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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda