Skip to content

Instantly share code, notes, and snippets.

@lusarz
Created April 6, 2019 08:40
Show Gist options
  • Save lusarz/3f1f7d77ed4a0ee766be1a33436198e1 to your computer and use it in GitHub Desktop.
Save lusarz/3f1f7d77ed4a0ee766be1a33436198e1 to your computer and use it in GitHub Desktop.
Mocking backend in vue component
// ArticlesDAO
import axios from 'axios';
export function findAll () {
axios.get('/api/articles');
}
// ArticlesList.spec.js
import ArticlesList from 'components/ArticlesList'
import { shallowMount } from '@vue/test-utils';
import * as ArticlesDAO from 'dao/ArticlesDAO';
import delay from 'utils';
describe('ArticlesList', () => {
let wrapper;
async function mountComponent () {
sinon.stub(ArticlesDAO, 'findAll').resolves([{ id: 1, name: 'Article 1' }, { id: 2, name: 'Article 2' }]);
wrapper = shallowMount(ArticlesList, {});
await delay();
}
afterEach(() => {
sinon.restore();
});
it('articles are displayed properly', async () => {
await mountComponent();
expect(wrapper.findAll('.article__name').wrappers.map(w => w.text())).to.deep.equal(['Article 1', 'Article 2']);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment