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

171
Vistas
How to create button react component?

I created simple React app and need to add Button Component. Unfortunately my code is not working. How I can fix it? Button realisation (React):

import React from 'react';

const Button = (props) => {
    return <button className="button">
        {props.children}
    </button>;
}

export { Button };

Test code:

import React from 'react';
import { shallow } from 'enzyme';

import Button from './Button';

describe('Button', () => {
    /**

     * children - button text

     */

    it('Button with text', () => {
        const component = shallow(<Button>Button</Button>);

        expect(component.html()).toEqual('<button class="button">Button</button>');
    });
});

files in dir

Error in test:

 Expected: "<button class=\"button\">Button</button>"
 Received: null
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

can you please try this,

it('Button with text', () => {
        const component = shallow(<Button>Button</Button>);

        expect(component.html()).toEqual('<button class=\"button\">Button</button>');
    });
about 4 years ago · Juan Pablo Isaza Denunciar

0

This import line:

import Button from './Button';

is asking the build to get the default export from the module, but you're exporting that component inside an object.

So either:

export default Button;

Or:

import { Button } from './Button';

(I'd also suggest adding parentheses around your JSX in your return, and importing some CSS specific to that component.)

function Button(props) {
  return (
    <button className="button">
      {props.children}
    </button>;
  );
}

export default Button;
about 4 years ago · Juan Pablo Isaza Denunciar
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