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

96
Visualizações
Testing existence of connected component with react-redux

I'm trying to test a component that wraps a connected component. So I have (simplified):

const InnerComponent = () => {
  return (
    <p>Hi!</p>
  )
}

const InnerComponentWrapper = connect()(InnerComponent)

const OuterComponent = () => {
  return (
    <div>
      <InnerComponentWrapper>
    </div>
  )
}

(Obviously there's more to these components, including state related stuff)

Now I'm trying to simply test that InnerComponent (or InnerComponentWrapper) is in OuterComponent. I'm using jest+enzyme. When I render OuterComponent (shallow or mount) all I can find in OuterComponent is an element with the tag of 'Connect' which doesn't have anything on it I can find that can tell me what element it's wrapping.

What I tried:

const enzymeWrapper = shallow(<OuterComponent />)
expect(enzymeWrapper.find('Connect').length).toBe(1) // pass
expect(enzymeWrapper.find('Connect(InnerComponentWrapper)').length).toBe(1) // fail
expect(enzymeWrapper.find('InnerComponentWrapper').length).toBe(1) // fail
expect(enzymeWrapper.find('InnerComponent').length).toBe(1) // fail

Thanks!

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

For me, this works (your 2nd attempt, marked as not working… perhaps you got some detail wrong, or things got fixed in a newer version?).

const enzymeWrapper = shallow(<OuterComponent />)
expect(enzymeWrapper.find('Connect(InnerComponentWrapper)')

Also, the Enzyme bug tracker points to this solution.

over 4 years ago · Santiago Trujillo Relatório

0

I found a solution, there could definitely be a better one, but this hacky one will do for now:

const enzymeWrapper = shallow(<OuterComponent />)
expect(enzymeWrapper.find('Connect').node.type.WrappedComponent({})).toEqual(InnerComponent({}))
over 4 years ago · Santiago Trujillo Relatório
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