• Jobs
  • About Us
  • Jobs
    • Home
    • Jobs
    • Courses and challenges
  • Businesses
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

472
Views
jest.mock No se puede encontrar el módulo

Tengo una función que usa la conexión mysql para hacer una consulta y estoy intentando probar esta función por unidad, para hacer esto necesito simular mysql. Sin embargo, cuando uso la función jest.mock para simular una conexión mysql, devuelve el siguiente error.

No se puede encontrar el módulo 'MySQLReplica' desde 'src/api/leaderboard/ranks/popularity.test.ts'

popularidad.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); }); });

servicios/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 3 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Show me some job opportunities
There's an error!