Created
April 6, 2019 08:40
-
-
Save lusarz/3f1f7d77ed4a0ee766be1a33436198e1 to your computer and use it in GitHub Desktop.
Mocking backend in vue component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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