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

134
Visualizações
Do I have a useless act call or is this a React 18 issue

I'm currently receiving an error in my testing:

12 |     const response = await axios.get('http://mock-api-call/weather/get-weather');
      13 |
    > 14 |     setWeather(response.data.result.weather);
         |     ^
      15 |   };
      16 |
      17 |   useEffect(() => {

The error is referencing my api call in component. Originally I was getting a error message from React to wrap my tests in an act function which I've followed it's prompts with, but don't know whether I've followed it correctly although all the tests are working I would like to know if I've used act incorrectly of whether this is a React 18 issue. Here are some tests examples:

jest.mock('axios');
const mockedAxios = axios as jest.Mocked<typeof axios>;

describe('Return Weather Component Data', () => {
  beforeEach(() => {
    mockedAxios.get.mockResolvedValue({
      data: {
        result: {
          weather: {
            forcast: 'Sunny',
            max: 28,
            min: 17,
            description: 'Clear skys all day with a warm summber breaze ariving in the afternoon',
          },
        },
      },
    });
  });

  test('should return description', async () => {
    await act(async () => {
      const { getByText } = render(<WeatherComponent />);
      waitFor(() => {
        expect(
          getByText('Clear skys all day with a warm summber breaze ariving in the afternoon'),
        ).toBeInTheDocument();
      });
    });
  });

  test('should return forcast', async () => {
    await act(async () => {
      const { getByText } = render(<WeatherComponent />);
      waitFor(() => {
        expect(getByText(/Sunny/i)).toBeInTheDocument();
      });
    });
  });
  test('should return temp', async () => {
    await act(async () => {
      const { getByText } = render(<WeatherComponent />);
      waitFor(() => {
        expect(getByText(/Sunny with a low of 17 and a high of 28/i)).toBeInTheDocument();
      });
    });
  });
});

error message:

   Warning: The current testing environment is not configured to support act(...)
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