Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

347
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!