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

514
Vistas
jest.mock Cannot find module

I have a function which uses mysql connection to make a query and i am attempting to unit test this function, to do this i need to mock mysql. However when i use the jest.mock function to mock a mysql connection it returns the following error.

Cannot find module 'MySQLReplica' from 'src/api/leaderboard/ranks/popularity.test.ts'

popularity.test.ts

import { MySQLReplica } from "@services/mysql.service";
import { IEntityLeaderboardQuery } from "./../leaderboard.interface";
import { PopularityRank } from "./popularity";
import { mocked } from "ts-jest/utils";
jest.mock("MySQLReplica");

describe("Leaderboard - Rank - Popularity", () => {
    afterAll(() => {
        MySQLReplica.end();
    });

    const mockedMySQLReplica = mocked(MySQLReplica, true);
    it("should get popularity scores", async () => {
        const query: IEntityLeaderboardQuery = {
            top: "10",
            entity_types: ["person"],
            region: "Europe",
            country: "Germany",
            end_date: "2021-06-15",
            start_date: "2021-06-01",
            rank: "popularity",
        };

        const result = await PopularityRank(query);
        console.log(result);
    });
});

services/mysql.service.ts

import mysql from "mysql2/promise";
import { Config } from "@config";

export const MySQLReplica = mysql.createPool({
    host: Config.db.replica.host,
    database: Config.db.replica.database,
    user: Config.db.replica.username,
    password: Config.db.replica.password,
    waitForConnections: true,
    connectionLimit: 500,
    queueLimit: 0,
});

export const MySQLWrite = mysql.createPool({
    host: Config.db.write.host,
    database: Config.db.write.database,
    user: Config.db.write.username,
    password: Config.db.write.password,
    waitForConnections: true,
    connectionLimit: 100,
    queueLimit: 0,
});

export const MySQLPreparedStatement = mysql.format;
over 4 years ago · Santiago Trujillo
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