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

[blog] testing flux applications #2234

Merged
merged 1 commit into from
Sep 24, 2014
Merged

Conversation

fisherwebdev
Copy link
Contributor

No description provided.

fisherwebdev added a commit that referenced this pull request Sep 24, 2014
[blog] testing flux applications
@fisherwebdev fisherwebdev merged commit 6f54ed7 into facebook:master Sep 24, 2014
@glenjamin
Copy link
Contributor

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.

fisherwebdev added a commit that referenced this pull request Sep 24, 2014
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
@fisherwebdev
Copy link
Contributor Author

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.

@fisherwebdev
Copy link
Contributor Author

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.

@glenjamin
Copy link
Contributor

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?

web-developer77 pushed a commit to web-developer77/facebook-react that referenced this pull request Jun 7, 2021
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
jerrydev0927 added a commit to jerrydev0927/react that referenced this pull request Jan 5, 2024
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
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.

2 participants