How it works...

While the testing of the mutations is pretty straightforward, I think the testing of the actions deserves some more explaining.

Since we didn't want to depend on external services for actions, we had to mock the axios service. We used the inject-loader, which takes the original library and mocks the parts we specify with arbitrary code (the @ symbol is a shorthand for src); in our case, we mocked the axios library and, precisely, the get method. We had to use the CommonJS syntax (with the require) because that's the only way to tell Webpack to use loaders in imports.

What we have done in the test is that we also mocked the commit function. Normally, this function calls a mutation that modifies the state. We just want to know ...

Get Vue.js 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.