Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

243
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!