1

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?

0

1 Answer 1

2

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);
  });
}); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.