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

Add section on unit testing middleware to docs #559

Merged
merged 2 commits into from
Aug 26, 2015
Merged

Add section on unit testing middleware to docs #559

merged 2 commits into from
Aug 26, 2015

Conversation

idolize
Copy link
Contributor

@idolize idolize commented Aug 17, 2015

Updated WritingTests.md with a section on how to test middleware.

The function signature for middlware is a little confusing, so I think this could add a lot of value.

gaearon added a commit that referenced this pull request Aug 26, 2015
Add section on unit testing middleware to docs
@gaearon gaearon merged commit e1faa7a into reduxjs:master Aug 26, 2015
@gaearon
Copy link
Contributor

gaearon commented Aug 26, 2015

Thanks

@gsklee
Copy link
Contributor

gsklee commented Sep 30, 2015

Can we expand upon this part a little bit more? Like what's inside singleDispatch.js and an example actions.js showing how the singleDispatch middleware is being used in the code.

@tristanls
Copy link

What is singleDispatch.js? This example is extremely confusing. Is this fictional middleware? Am I supposed to know how to implement this module? The string singleDispatch only occurs in the doc file and nowhere else in this repo.

@markerikson
Copy link
Contributor

Yeah, it appears to be a fictional middleware that is referenced in the unit test examples, but not actually shown anywhere.

@IndependentContractor
Copy link

Has anyone figured out how to implement singleDispatch or what it might look like?

@brigand
Copy link
Contributor

brigand commented Jul 9, 2017

@IndependentContractor my guess is that it'd either be one dispatch ever, or one dispatch per action type.

let dispatched = false;
const singleDispatch = store => next => action => {
  if (dispatched) return;
  dispatched = true;
  next(action);
}
let dispatchedTypes = new Map();
const singleDispatch = store => next => action => {
  if (dispatchedTypes.get(action.type)) return;
  dispatchedTypes.set(action.type, true);
  next(action);
}

@brigand
Copy link
Contributor

brigand commented Jul 9, 2017

I'm going to take a stab at improving these docs.

brigand added a commit to brigand/redux that referenced this pull request Jul 9, 2017
@brigand
Copy link
Contributor

brigand commented Jul 9, 2017

#2496

timdorr pushed a commit that referenced this pull request Jul 10, 2017
* writing tests for middleware example changed, #559

* note about mock impls

* backticks to single quotes

* better first test

* semi

* back ticks around `create`
seantcoyote pushed a commit to seantcoyote/redux that referenced this pull request Jan 14, 2018
* writing tests for middleware example changed, reduxjs#559

* note about mock impls

* backticks to single quotes

* better first test

* semi

* back ticks around `create`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants