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

244
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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