Skip to content Skip to sidebar Skip to footer

Vue And Jest Unit Testing Components

I'm pretty new in Vue js, and I'm starting with unit testing with Jest. I don't have any idea where and how to start. I have this piece of Vue code that i would like to test using

Solution 1:

You can read vue-test-utils official documentation it's very clear and helpful. Also to learn how to mock functions, stubs and other test things see Jest docs.

And with your example - use propsData instead of props(check docs above) and you should end each your test case with some assertion (checking expectations):

describe('User', () => {
   it('Should substract four letters', () => {
      const wrapper = shallowMount(User, {
      propsData: {
        user: 'User00000000'
      }
    })
   // check that span element has correct substringexpect(wrapper.find(".user span").text()).toBe('User');
  })
})

Post a Comment for "Vue And Jest Unit Testing Components"