Vue-apollo: Testing documentation

Created on 23 Mar 2018  路  5Comments  路  Source: vuejs/vue-apollo

Hello I am new to the vue ecosystem and a work project has me using vue + apollo. I am using jest as my test suite and searching for documentation on how to setup my test suite to mock my queries and mutations. I have not found anything in the documentation, or searching through google for _how to_ articles. I did find this StackO post that remains unanswered.

Are there any prescribed methods for setting up the mocks/suite? I am willing to add documentation to the project on testing if I can wrap my head around the _how to_ of setting up the test suite. Thanks for your time and consideration.

Most helpful comment

Maybe in the future when we'll have a documentation website.

All 5 comments

I recommend to use vue test-utils if you don't already. Then you have to mock everything related to apollo. If you have queries, just use wrapper.setData. If you have mutations, mock them like this:

const mutate = jest.fn()
const wrapper = mount(MyComponent, {
  mocks: {
    $apollo: {
      mutate,
    },
  },
})
// ...
expect(mutate).toBeCalled()

@Akryum thanks

Is adding documentation on testing something you want the project to have or do you feel it's outside the scope of the project?

Maybe in the future when we'll have a documentation website.

Anyone landing here from a web search, there is some documentation for testing now: https://akryum.github.io/vue-apollo/guide/testing.html

Not sure that the above link is still valid. (I got a 404) But for future web travelers, I think these are the docs here: https://vue-apollo.netlify.com/guide/testing.html#simple-tests

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shomodj picture shomodj  路  15Comments

ffxsam picture ffxsam  路  28Comments

beeplin picture beeplin  路  33Comments

alidlorenzo picture alidlorenzo  路  72Comments

lorensr picture lorensr  路  19Comments