5

I ran into a problem when running a component test that has a line inside it: const route = useRoute(). I get an error: Cannot read properties of undefined (reading 'path'). Here is the test:

describe('Tariff card', () => {
  const options = {
    props: {
      name: 'test',
      tariffId: 2,
      price: 3990,
      maxCompanies: 1,
      maxCampaigns: 5,
      tariffNum: 2,
      isFree: false,
      duration: 30,
    },
    global: {
      plugins: [createTestingPinia()],
    },
  }

  it('render tariff card', async () => {

    jest.mock('vue-router', () => ({
      useRoute: jest.fn(() => ({ path: '/' }))
    }))

    render(TariffCard, options)
  })
})

0

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.