Skip to content

Instantly share code, notes, and snippets.

View kuroski's full-sized avatar
👨‍💻
coding

Daniel Kuroski kuroski

👨‍💻
coding
View GitHub Profile
...
...
it('calls "submitted" event when submitting form', () => {
// arrange
const expectedUser = 'kuroski'
const { wrapperMounted, button, inputMounted } = build()
inputMounted().element.value = expectedUser
// act
inputMounted().trigger('input')
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 }
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 })
<script>
export default {
name: 'UserSearchForm',
data() {
return {
username: ''
}
}
}
</script>
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: [
@kuroski
kuroski / api.js
Created September 11, 2018 13:43
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) {
@kuroski
kuroski / api.spec.js
Last active September 11, 2018 12:56
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'
export default {
SET_USER(state, user) {
state.user = { ...user }
}
}
import mutations from '@/store/mutations'
import initialState from '@/store/state'
import user from './fixtures/user'
describe('mutations', () => {
let state
beforeEach(() => {
state = { ...initialState }
})
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) {