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

352
Visualizações
Jest Vuejs Test - TypeError: Cannot read properties of undefined (reading 'params')

I started first time to test my vuejs application. In my application I have a list of clients, and when you click on client, you go to that clients page, which I am try to test right now. But my test fails before I started with this error:

TypeError: Cannot read properties of undefined (reading 'params')

created() {
   this.clientid = this.$route.params.id;
                                   ^
   this.getClient();
}

I tried to set this into my test:

describe('Client', () => {
    it('should mount Client', () => {
      const wrapper = mount(Client, {
        data: () => ({
          route: {
            params: {
              id: ''
            }
          },
        }),
      });
      expect(wrapper.exists()).toBe(true);
    });
  });

Can you help me understand how to give this params a value through the test?

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

0

There has been many different answers on the net, but the for the vue1. This worked for me:

describe('Client', () => {
  it('should mount Client', async () => {
    const wrapper = shallowMount(Client, {
      global: {
        mocks: {
          $route: {params: { id: ""}},
        }
      }
    })
    expect(wrapper.exists()).toBe(true);
  });
}); 
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