-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Enhancement for testAction helper method #939
Comments
Thumps up, I thinks this is a great idea! I've found myself in similar situation, thinking how to test actions that dispatch other actions. However, IMHO, I think dispatched actions shouldn't go to |
@kingstenbanh I was looking for the exact information you are proposing to add in the Vuex docs (I even posed in the Vuejs forum in hopes of finding a solution). Using your proposed Since the Vuex docs explicitly recommend composing actions from other actions using One other thing the docs recommend is returning Promises in actions since they can be asynchronous. Any ideas on how the a test for async Vuex actions would look? Thanks for posting, I found this thread very useful. |
@egardner You could try using spies: const dispatch = sinon.spy();
const state = {
// ...
};
actions.myAction({ dispatch, state }, someParameter)
.then(() => {
expect(dispatch.args).to.deep.equal([
[ 'firstDispatchedAction' ],
[ 'actionWithParameter', someParameter ],
]);
}); |
I have created a pull request to add spies as an alternative to the |
Enhancment that comes handy when want to make sure if no extra commits were made
|
We've bumped into the same problem, we added support for actions like this: https://gitlab.com/gitlab-org/gitlab-ce/blob/master/spec/javascripts/helpers/vuex_action_helper.js#L21 (Still needs some improvements, but it might be usefull for anyone else) |
Closing due to inactivity. Docs have been updated few times, and if still need to discuss about this topic, we should open another issue referencing the latest docs. |
What problem does this feature solve?
The current API for the testAction method helps reducing the need to stub out the action context (state, rootState, commit, etc). However, the recommended method assumes that each action will only trigger a state mutation (commit) and access previous data (state), which is not true in real-world and large-scale project. In my project, an action might need to dispatch another action, access the state of another module (rootState), or some getters. The current method doesn't give us the full access of the action context resulting in a lot of mocking in writing tests. I bet a lot of user out there are experiencing the same problem.
What does the proposed API look like?
The proposed API will create a similar signature with the way an action is created.
Here is the proposed testAction.
The text was updated successfully, but these errors were encountered: