-
Notifications
You must be signed in to change notification settings - Fork 47.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
[blog] testing flux applications #2234
Conversation
b0b4e32
to
9952a54
Compare
[blog] testing flux applications
I'm not sure if this is a useful place to leave this comment, but i'll try it anyway: Is there an advantage to extracting the registered callback from the mocked dispatcher over just not mocking the dispatcher? There's a reasonable chunk of the blog post taken up explaining the gymnastics being done to extract the dispatcher callback, when (as I understand it), dontMock would be a bit more straightforward. |
GitHub154 [react] fisherwebdev closed pull request #2234: [blog] testing flux applications (master...master) #2234 GitHub183 [react] fisherwebdev pushed 2 new commits to master: 67eeed6...6f54ed7 GitHub183 react/master 9952a54 fisherwebdev: [blog] testing flux applications GitHub183 react/master 6f54ed7 Bill Fisher: Merge pull request #2234 from fisherwebdev/master... ChanServ has changed mode: +o yungsters GitHub16 [react] fisherwebdev pushed 1 new commit to 0.11-stable: 99a45a5 GitHub16 react/0.11-stable 99a45a5 fisherwebdev: [blog] testing flux applications
You could certainly write tests that way, and I have at times followed that route. There is nothing "wrong" with it per se, it simply adds another thing (theoretically, or who knows, maybe practically) to consider when things don't work as expected. The ideal of unit tests is to test a single unit. Integration tests, on the other hand, test the interaction between multiple parts of a system. So what you are describing is moving toward an integration test, not a unit test. Whether or not mocking the dispatcher matters in practice is a matter of debate, but in theory, at least, we can all see that we're no longer testing the store in isolation if we don't mock the dispatcher. In that case, there is always the outside chance that it's something outside the store that's to blame for failing tests -- you won't know exactly where to look to find the bug. |
By the way, on this topic -- definitely check out that classic Martin Fowler essay that I recommended at the end of the post: Mocks Aren't Stubs -- Fowler might agree with the point you're making, but he has sympathy for both sides of the argument. |
Thanks for the thoughtful response - I'd gotten into the habit of my current way of approaching mocking, so it's good to be reminded there's more than one valid way! Another thing that occurred to me on re-reading is that there are no assertions on the 'change' event being emitted. Is this something you think would be worth including in store tests in general? |
GitHub154 [react] fisherwebdev closed pull request #2234: [blog] testing flux applications (master...master) facebook/react#2234 GitHub183 [react] fisherwebdev pushed 2 new commits to master: facebook/react@67eeed6...6f54ed7 GitHub183 react/master 9952a54 fisherwebdev: [blog] testing flux applications GitHub183 react/master 6f54ed7 Bill Fisher: Merge pull request #2234 from fisherwebdev/master... ChanServ has changed mode: +o yungsters GitHub16 [react] fisherwebdev pushed 1 new commit to 0.11-stable: facebook/react@99a45a5 GitHub16 react/0.11-stable 99a45a5 fisherwebdev: [blog] testing flux applications
GitHub154 [react] fisherwebdev closed pull request #2234: [blog] testing flux applications (master...master) facebook/react#2234 GitHub183 [react] fisherwebdev pushed 2 new commits to master: facebook/react@67eeed6...6f54ed7 GitHub183 react/master 9952a54 fisherwebdev: [blog] testing flux applications GitHub183 react/master 6f54ed7 Bill Fisher: Merge pull request #2234 from fisherwebdev/master... ChanServ has changed mode: +o yungsters GitHub16 [react] fisherwebdev pushed 1 new commit to 0.11-stable: facebook/react@99a45a5 GitHub16 react/0.11-stable 99a45a5 fisherwebdev: [blog] testing flux applications
No description provided.