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

136
Visualizações
How to test that a react component renders both its states correctly?

Before rendering all the UI elements I check that the relevant state parameters aren't null.

render() {
        if(this.state.one === null 
            || this.state.two === null 
            || this.state.three === null){
            return <div/>
        }
        return(
            // divs for actual UI 
        )
}

Then in my test I check that component matches the snapshot, the initial state has null parameters, so the snapshot will only return the one empty div. So, that works, I can check that the component isn't rendered when it shouldn't be, but how can I add another snapshot, or something else, to see that everything is rendered correctly when the state no longer contains null?

import React from 'react';
import { shallow } from 'enzyme';
import TheUIComponent from './TheUIClass';

let component;

beforeEach(() => {
    component = shallow(<TheUIComponent/>);
});

describe('UIComponent', () => {
    it('should render correctly', () => {
        expect(component).toMatchSnapshot();
        
    });
}
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