You can check this article about testing before start with the workshop. Remember that all the examples are only examples, not necessary the best practise.
- Testing services/actions/helpers
- Test all the public methods
- Testing components
- Test only logic, not UI (use e2e for that)
- Try to move all the data logic to services/actions/helpers
const wrapper = shallowMount<any>(CityAddComponent, {
localVue
});
await nextTick();
expect(wrapper.vm.testableMethods(2)).to.equal(3);
const spyCitiesServiceRemove = sinon.stub()
mockInject(wrapper.vm, 'citiesService', {
remove: spyCitiesServiceRemove
})
await nextTick()
wrapper.vm.remove();
expect(spyCitiesServiceRemove).to.be.called;
spyCitiesServiceRemove.restore();
const route = `/api`
const spyFetchCitiesSearch = fetchStub(JSON.stringify(responseObject));
await citiesService.search();
expect(spyFetchCitiesSearch.withArgs(route)).to.be.called;