0

I'm using vue-test-utils with jest, I have router-link being rendered in a Login Component. I'm passing router to the component as well.

There is data called 'email', on its update forgot link get's updated.

Following unit-test checks that.

it("updates forgot password link correctly", done => {
    wrapper.setData({
      user: {
        email: 'a@a.com',
        password: '',
      }
    });
    Vue.nextTick(() => {
      expect(wrapper.find('a').element.href).toEqual('/forgot-password/?email=a@a.com');
      done();
    })
  })

I'm creating wrapper using following code:

const wrapper = mount(LoginComponent, {
    localVue,
    sync: false,
    stubs: {
      RouterLink: RouterLinkStub,
    },
    mocks: {
      $route: {
        path: "/login",
        meta: {
          signout: false
        }
      }
    }
  });

What is the correct way to update component data and then check the re-rendered component ?

Farhan Tahir
  • 2,096
  • 1
  • 14
  • 27

1 Answers1

2

Try to use async/await , for ex:


it('blah blah', async () => {
  wrapper.setData({
      user: {
        email: 'a@a.com',
        password: '',
      }
    });

  await Vue.nextTick()

  expect(wrapper.find('a').element.href).toEqual('/forgot-password/?email=a@a.com')
})

see example here https://vue-test-utils.vuejs.org/guides/testing-async-components.html

huyttq
  • 21
  • 2