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
Fixtures are the part of a test suite that set the stage for our specs. In this video, we’ll write code to run before every spec and also before each test spec that makes testing simpler.
Resources
Video review
- Mocha provides useful functions to help us set up conditions for our tests, like creating test objects and simulating the conditions inside our app
- The "setup" phase is the part of our tests where we set up conditions for testing
- Mocha splits the setup process into two blocks: the stuff we set up before the entire series of tests, and the stuff we set up before each individual test
- Mocha provides the hooks
before(),after(),beforeEach(), andafterEach()to set up preconditions and clean up after your tests -
beforeEach()works like before, only it will run the function before each spec, instead of just once at the start of the suite
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
we're still just writing JavaScript.
0:00
You'll want to follow the same best
practices you use when writing
0:01
any JavaScript program.
0:04
We should keep our test dry and tidy.
0:06
In this stage, we'll explore some handy
ways to avoid repeating ourselves.
0:08
We'll also expand our tests
to build our confidence and
0:13
the code we've written so far.
0:16
So far, I've been writing the dependencies
for every test within each spec.
0:18
For example, in our check for
0:23
ship test suite, I wrote a new
player object for every test.
0:24
So the first test has a player, and
the second test has the same exact player.
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