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

393
Views
How Do I Suppress A Specific Error In Jest Tests

I'm trying to suppress a specific error in our Jest tests as we've got plans to resolve it later, but until then we don't want these errors potentially hiding any true errors.

The errors occur across the codebase so my current strategy is to rewire the console.error function in our jest setup file.

I've taken two different attempts, both almost working however now when they report a true error - they're adding a new line onto the error trace.

Attempt 1:

const originalError = console.error.bind(console.error);
jest.spyOn(global.console, 'error').mockImplementation((message) => {
  if (
    !message
      .toString()
      .includes(
        'Warning: An update to SettingsPanel inside a test was not wrapped in act'
      )
  ) {
    originalError(message);
  }
});

Attempt 2:

const { error } = console;
global.console = {
  ...console,
  error: (errorMessage) =>
    !errorMessage
      .toString()
      .includes(
        'Warning: An update to SettingsPanel inside a test was not wrapped in act'
      ) && error(errorMessage),
};

Both of these will log a valid error - i.e. 'Warning: Each child in a list should have a unique "key"' - However instead of pointing me to the code with the issue it points me back here

console.error
    Warning: Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/docs/lists-and-keys.html#keys for more information.%s

      18 |       .includes(
      19 |         'Warning: An update to SettingsPanel inside a test was not wrapped in act'
    > 20 |       ) && error(errorMessage),
         |            ^
      21 | };

      at Object.error (jest.setup.js:20:12)
      at printWarning (node_modules/react/cjs/react.development.js:315:30)
      at error (node_modules/react/cjs/react.development.js:287:5)
      at validateExplicitKey (node_modules/react/cjs/react.development.js:1630:5)
      at validateChildKeys (node_modules/react/cjs/react.development.js:1656:9)
      at Object.createElementWithValidation [as createElement] (node_modules/react/cjs/react.development.js:1806:7)
      at src/js/components/SettingsPanel/DataListAutocompleter/DataListAutocompleter.tsx:85:13

I've searched and searched and all I can find are questions about silencing all errors or silencing a specific test - nothing I've found has helped me solve this.

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