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

272
Visualizações
Cannot shallow render a component using IntlProvider

I have the following component, using Flow:

//@flow

import React, { type Node } from 'react';
import { useIntl } from 'react-intl';

type Props = { balance: Object };

const AvailableDiscount = ({ balance }: Props): Node => {
  const { formatMessage, locale } = useIntl();

  return (
    <div>
      {formatMessage({ id: 'XAM_DISCOUNT_DETAILS' })}: {balance.value}
    </>
  );
};

And while testing it, I seem to have a problem when trying it so mount it with shallow, using Enzyme:

// @flow

import { mount, shallow } from 'enzyme';
import React from 'react';
import { IntlProvider } from 'react-intl';

import balance from '../../../utils/testHelpers/testData/customerBalance';
import AvailableDiscount from './AvailableDiscount';

describe('AvailableDiscount', () => {
  it('renders correctly', () => {
    const component = <AvailableDiscount balance={balance} />;
    const wrappingOptions = {
      wrappingComponent: IntlProvider,
      wrappingComponentProps: {
        locale: 'en',
        defaultLocale: 'en',
        messages: {},
      },
    };
    const mountedComponent = mount(component, wrappingOptions); // <-- This works
    const shallowComponent = shallow(component, wrappingOptions); // <-- This does NOT work
  });
});

It tells me that the component does not seem to be wrapped in the provider.

enter image description here

While this seems to work for mount, shallow keeps giving me this error. Why could this be?

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