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

480
Visualizações
Tests in React are passing if run separately but throw error when both of them are run

Having the following testing file:

import { render } from '@testing-library/react';

import '@testing-library/jest-dom';
import TaskModal from './task-modal';

describe('TaskModal', () => {
  const title = 'title';
  const selectedOption = { id: '1', name: 'test' };
  const options = [{ id: '1', name: 'test' }];
  it('should render successfully', () => {
    const { baseElement, getByText } = render(
      <TaskModal
        title={title}
        open={true}
        toggle={jest.fn()}
        initialScriptNameSelectedOption={selectedOption}
        scriptNameOptions={options}
      />
    );
    expect(baseElement).toBeTruthy();
    expect(getByText(title)).toBeTruthy();
  });

  it('should check if TaskModal renders Textarea successfully', () => {
    const { getByTestId } = render(
      <TaskModal
        hasTextarea
        title={title}
        open={true}
        toggle={jest.fn()}
        initialScriptNameSelectedOption={selectedOption}
        scriptNameOptions={options}
      />
    );
    const textarea = getByTestId('has-textarea');
    expect(textarea).toBeInTheDocument();
  });
});

When I run each test separately they pass, when I run the whole file, the second test fails with the following message:

Error: Uncaught [ReferenceError: IntersectionObserver is not defined]

Why is this happening?

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