Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed JavaScript Unit Testing!
You have completed JavaScript Unit Testing!
Preview
In this video, I'll show you how I would reorganize the random square function to be more testable.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Each of these functions really
does two different things.
0:00
First they build a random location,
then they do something with that location,
0:01
like fire a shot or place a ship.
0:06
In programming, we call this tight
coupling when two distinct functions
0:10
are bundled up so that they can
only really be used together.
0:14
Now a hallmark of tightly coupled code
is that it makes our job of writing unit
0:17
tests harder.
0:21
So to refactor this code I
think we can actually just
0:23
abstract those two ideas apart.
0:25
We see that the same code appears
in both the computerFire and
0:28
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up