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

107
Vistas
Mocking values inside function

I'm using SinonJS, Mocha and chai for my unit tests.
I want to know if it's possible to mock the value of a variable or the return of a function with Sinon.

Imagine I have this:

testeA.ts

const getA = () => 20

export function test() {
  const valA = getA();
  const result = valA * 2; 
  return result;
}

Is it possible to mock the value returned by getA() and/or valA value inside my tests? Maybe use the mock instead of the actual method.

myTest.spec.ts

import * as test from './testeA'
import * as chai from 'chai'
import * as sinon from 'sinon'

const expect = chai.expect

describe('First Test', () => {
  it('should run the test', () => {    
    const myMock = sinon.mock('test') // Mock the function

    // MOck the values somehow
 
    
    expect(test.test()).to.be.equal(30)
  })
})

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