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

270
Visualizações
Cómo simular módulos exportados predeterminados con broma

El problema

Estoy tratando de simular la parte exportada predeterminada de un módulo, que se ve así:

 // test.js const testVariable = { blabla: { test: 'testContent' } }; export const anotherNotNeedToMockVariable = {}; export default testVariable;

La variable que realmente necesito simular es test .

lo que he probado

Esta implementación me da error: Cannot spy the default property because it is not a function

 // toTestModule.js import test from './test' export const toTestModuleFunc = async () => { console.log('variable mocked', test.blabla.test); return test.blabla.test; }; import * as test from '../test' import {toTestModuleFunc} from '../toTestModule' describe('test', () => { it('with jest.mock()', async () => { const newValue = 'newValue'; jest.mock('../test', () => ({ blabla: { test: newValue } })); const value = await toTestModuleFunc(); // this fails expect(value).toEqual(newValue); }); it('with jest.spyOn()', async () => { const newValue = 'newValue'; jest.spyOn(test, 'default', 'get').mockImplementation(() => { return ({ blabla: { test: newValue } }); }); const value = await toTestModuleFunc(); // this fails expect(value).toEqual(newValue); }); });

Si cambio jest.spyOn(test, 'default') a jest.spyOn(test, 'default', 'get') me da otro error: Property default does not have access type get

Traté de usar la función jest.mock() , pero no funciona porque nunca devuelve el valor simulado.

Realmente apreciaría cualquier ayuda.

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