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
... | |
... | |
it('calls "submitted" event when submitting form', () => { | |
// arrange | |
const expectedUser = 'kuroski' | |
const { wrapperMounted, button, inputMounted } = build() | |
inputMounted().element.value = expectedUser | |
// act | |
inputMounted().trigger('input') |
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
import { shallowMount, mount, createLocalVue } from '@vue/test-utils' | |
import ElementUI from 'element-ui' | |
import VUserSearchForm from '@/components/VUserSearchForm' | |
const localVue = createLocalVue() | |
localVue.use(ElementUI) | |
describe('VUserSearchForm', () => { | |
const build = () => { | |
const options = { localVue } |
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
import { shallowMount, mount, createLocalVue } from '@vue/test-utils' | |
import ElementUI from 'element-ui' | |
import VUserSearchForm from '@/components/VUserSearchForm' | |
const localVue = createLocalVue() | |
localVue.use(ElementUI) | |
describe('VUserSearchForm', () => { | |
const build = () => { | |
const wrapper = shallowMount(VUserSearchForm, { localVue }) |
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
<script> | |
export default { | |
name: 'UserSearchForm', | |
data() { | |
return { | |
username: '' | |
} | |
} | |
} | |
</script> |
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
import Vue from 'vue' | |
import Router from 'vue-router' | |
const UserView = () => import('@/views/UserView') | |
Vue.use(Router) | |
export default new Router({ | |
mode: 'history', | |
base: process.env.BASE_URL, | |
routes: [ |
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
import axios from 'axios' | |
import httpAdapter from 'axios/lib/adapters/http' | |
const instance = axios.create({ | |
baseURL: 'https://api.github.com', | |
adapter: httpAdapter, | |
}) | |
export default { | |
searchUser(username) { |
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
import flushPromises from 'flush-promises' | |
import nock from 'nock' | |
import api from '@/api' | |
import userFixture from './fixtures/user' | |
describe('api', () => { | |
it('searches for the user', async () => { | |
// arrange | |
const expectedUser = 'kuroski' |
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
export default { | |
SET_USER(state, user) { | |
state.user = { ...user } | |
} | |
} |
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
import mutations from '@/store/mutations' | |
import initialState from '@/store/state' | |
import user from './fixtures/user' | |
describe('mutations', () => { | |
let state | |
beforeEach(() => { | |
state = { ...initialState } | |
}) |
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
import api from '@/api' | |
export default { | |
SEARCH_USER({ commit }, { username }) { | |
return new Promise(async (resolve, reject) => { | |
try { | |
const user = await api.searchUser(username) | |
commit('SET_USER', user) | |
resolve(user) | |
} catch(error) { |