Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

201
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda