Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

130
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda