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

198
Visualizações
Jest : Test method in reactjs component

I have functional component FilterBar -

const FilterBar=()=>{

....
....
useEffects..
states...

function apiCallToFilters()
{
  ...
  ...
}

...
..

}

Since entire code cannot be shared , I have shared a structure and a method which I want to test from jest.

I have written FilterBar.test.tsx -

describe('Filter Bar', () => {
  it('All Api Calls', () => {
    const wrapper = shallow(<FilterBar />);
    expect(wrapper.instance().apiCallToFilters //not able to find apiCallToFilters method here
  });
});

I have followed this question from SO.

After having wrapper.instance(). I am getting below properties and methods -

context
forceUpdate
getSnapshotBeforeUpdate
props
render
setState
shouldComponentUpdate
state

How can I test apiCallToFilters method in FilterBar from jest?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Enzyme - the library that gives programmatic access to a component instance's properties can only give access to properties that are accessible from outside as it cannot violate JavaScript's encapsulation principles.

I cannot see what kind of a component you are using from in your example code, but I would strongly advise you to convert it to a class component and change the apiCallToFilters function into a method (by removing the function keyword).

Link to a thread where this is called out can be found here.

about 4 years ago · Juan Pablo Isaza 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