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

245
Vistas
Functional component does not work when importing it in test

I have a functional component Foo.js that looks like this:

const Foo = () => {
  return (
    <View></View>
  )
}
export default Foo

This component works fine when rendering it in the app.


The issue is when trying to test the component like this:

import renderer from 'react-test-renderer'
import Foo from './Foo'
test('testing', () => {
  const component = renderer.create(<Foo />)  <--- Error occurs
})

An error occurs when running this test (when calling renderer.create), saying: Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.


The strange thing is that the test passes without any error if I put the component inside the test file:

const Foo = () => {
  return (
      <View></View>
  )
}
test('testing', () => {
  const component = renderer.create(<Foo />)
})
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Turns out that the cause for this was that the exported component got mocked, due to that I had automock set to true in my jest config.

Changing this in jest.config.js:

automock: true

Into this:

automock: false

Resolves the issue.


Question: Why is the automocked component not returning anything? Could that be solved in some way so that it would work having automock set to true?

about 4 years ago · Juan Pablo Isaza Denunciar
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