我有这样的js代码:
const Repository = axios.create( {
baseURL: process.env.VUE_APP_API_HOST
} );
const state = { ... }
const getters = { ... }
const mutations = { ... }
const actions = {
fetch: async ( { commit, getters }, { apiPath, id } ) => {
const response = await Repository.get( apiPath );
commit( 'setArticleList', { response.data, id } );
commit( 'changeApiStatus', { status: 'success', id } );
}
};
export const articleList = {
namespaced: true,
state,
getters,
mutations,
actions
};
我有一个这样的玩笑代码:
import { store as store2 } from './store';
describe( 'store article_list test: ', () => {
let store;
beforeEach( () => {
store = new Vuex.Store( store2 );
} );
describe( 'test actions', () => {
test( 'get value correctly', async () => {
const apiPath = 'api/v1/article_list.json';
const id = 1;
await store.dispatch( 'articleList/fetch', { apiPath, id } );
} );
} );
} );
这是商店代码:
import Vue from 'vue';
import Vuex from 'vuex';
import { articleList } from '@/store/modules/article_list';
Vue.use( Vuex );
export const store = {
modules: {
articleList
}
};
export default new Vuex.Store( store );
await store.dispatch( 'articleList/fetch', { apiPath, id } );
当前此代码有一个Error: Error: connect ECONNREFUSED 127.0.0.1: 8080
错误
我想模拟这部分const response = await Repository.get( apiPath );
但是我不知道如何在玩弄vuex商店时模拟变量。
让我知道您是否会模拟该部分。
感谢您阅读我的问题。