Skip to content
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

Async Actions — Unit Testing #20

Closed
mxstbr opened this issue Dec 17, 2015 · 4 comments
Closed

Async Actions — Unit Testing #20

mxstbr opened this issue Dec 17, 2015 · 4 comments
Assignees
Labels
Milestone

Comments

@mxstbr
Copy link
Member

mxstbr commented Dec 17, 2015

Since testing async actions isn't really useful, you have to export the non-async actions too to test them. This results in functions being exposed that shouldn't be. Example:

export function asyncChangeProjectName(name) {
  return function(dispatch) {
    return dispatch(changeProjectName(name));
  }
}

export function asyncChangeOwnerName(name) {
  return function(dispatch) {
    return dispatch(changeOwnerName(name));
  }
}

export function changeProjectName(name) {
  return { type: CHANGE_PROJECT_NAME, name };
}

export function changeOwnerName(name) {
  return { type: CHANGE_OWNER_NAME, name };
}

changeOwnerName and changeProjectName shouldn't really be accessible from the outside, which they are right now so the unit tests can import them.

mxstbr added a commit that referenced this issue Dec 17, 2015
Fix unit tests by exposing the non-async actions too. Non-optimal solution, looking for a better one in #20
@mxstbr mxstbr changed the title Async action unit testing Async Actions — Unit Testing Dec 17, 2015
@mxstbr
Copy link
Member Author

mxstbr commented Dec 18, 2015

This issue might be worth reading through: reduxjs/redux-thunk#14

@mxstbr mxstbr added this to the v3.0 milestone Dec 24, 2015
@mxstbr
Copy link
Member Author

mxstbr commented Dec 25, 2015

Using the rewire module seems like the right way to go, see here

@mxstbr mxstbr self-assigned this Dec 25, 2015
mxstbr added a commit that referenced this issue Dec 25, 2015
Using the rewire module, we now don't have to export our hidden non-async actions to test them, we can get them using rewire. Makes for a much less error-prone application writing, it's a bit more overhead for the unit tests writing, thoughI think that's worth it.

Also see https://stackoverflow.com/questions/14874208/how-to-access-and-test-an-internal-non-exports-function-in-a-node-js-module

Closes #20
@mxstbr
Copy link
Member Author

mxstbr commented Dec 31, 2015

Done with 417362f!

@mxstbr mxstbr closed this as completed Dec 31, 2015
@mxstbr mxstbr reopened this Jan 14, 2016
@mxstbr mxstbr closed this as completed Jan 14, 2016
@lock
Copy link

lock bot commented May 30, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant