Commit a53f3e3a authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch...

Merge branch '21775-helpers-vuex_action_helper-function-is-a-little-bit-confusing-to-use' into 'master'

Allow passing named parameters to testAction function

See merge request gitlab-org/gitlab!48435
parents e56279d0 2e9a1608
......@@ -4,7 +4,7 @@ const noop = () => {};
* Helper for testing action with expected mutations inspired in
* https://vuex.vuejs.org/en/testing.html
*
* @param {Function} action to be tested
* @param {(Function|Object)} action to be tested, or object of named parameters
* @param {Object} payload will be provided to the action
* @param {Object} state will be provided to the action
* @param {Array} [expectedMutations=[]] mutations expected to be committed
......@@ -39,15 +39,42 @@ const noop = () => {};
* [], // expected actions
* ).then(done)
* .catch(done.fail);
*
* @example
* await testAction({
* action: actions.actionName,
* payload: { deleteListId: 1 },
* state: { lists: [1, 2, 3] },
* expectedMutations: [ { type: types.MUTATION} ],
* expectedActions: [],
* })
*/
export default (
actionArg,
payloadArg,
stateArg,
expectedMutationsArg = [],
expectedActionsArg = [],
doneArg = noop,
) => {
let action = actionArg;
let payload = payloadArg;
let state = stateArg;
let expectedMutations = expectedMutationsArg;
let expectedActions = expectedActionsArg;
let done = doneArg;
if (typeof actionArg !== 'function') {
({
action,
payload,
state,
expectedMutations = [],
expectedActions = [],
done = noop,
) => {
} = actionArg);
}
const mutations = [];
const actions = [];
......
import MockAdapter from 'axios-mock-adapter';
import { TEST_HOST } from 'helpers/test_constants';
import axios from '~/lib/utils/axios_utils';
import testAction from './vuex_action_helper';
import testActionFn from './vuex_action_helper';
describe('VueX test helper (testAction)', () => {
const testActionFnWithOptionsArg = (...args) => {
const [action, payload, state, expectedMutations, expectedActions, done] = args;
return testActionFn({ action, payload, state, expectedMutations, expectedActions, done });
};
describe.each([testActionFn, testActionFnWithOptionsArg])(
'VueX test helper (testAction)',
testAction => {
let originalExpect;
let assertion;
let mock;
......@@ -163,4 +170,5 @@ describe('VueX test helper (testAction)', () => {
testAction(asyncAction, null, {}, assertion.mutations, assertion.actions, done);
});
});
},
);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment