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

234
Vistas
Mocking BigNumber library for front end tests with Jest

I'm looking for some help with mocking the BigNumber library for some Jest tests.

In my webapp I have some BigNumber calculations such as:

const a = '30';
const b = '20';

const BigNA = BigNumber.from(a);
const BigNB = BigNumber.from(b);
const conversion = BigNumber.from(Math.pow(10, 12));

const AMinusB = BigNA.sub(BigNB);
const AMinusBConversion = AMinusB.div(conversion)

The above is just a made up example but closely mirrors what is happening in my codebase. Now to test this I need to mock the BigNumber library so that it is always returned with the from, sub, div, gt etc methods on it, so the next BigNumber calculation can be performed.

In my tests I have the following:

const BigNumber: any = {
  from: () => BigNumber
  sub: () => BigNumber,
  gt: () => true,
  div: () => jest.fn(() => '10'),
};

jest.mock('@ethersproject/bignumber', () => ({
  BigNumber,
}));

I have also tried many variations of the above mock such as:

from: () => jest.mock(() => BigNumber),

from: () => ({ ...BigNumber })

However in all cases the test either hangs out entirely, or throws a BigNA.sub is not a function error when it hits the sub or div calls.

Would be really appreciated if anyone has any insight or pointers in regards to mocking this BigNumber library as I'm entirely out of ideas at this point.

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