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
When we set something up before our tests, we need to be sure we tear it down afterward too. In this video, we’ll use Mocha functions called 'after' and 'afterEach'.
Resources
Video review
- Mocha provides a "teardown" phase to remove unwanted variables
- If your tests change your development environment, like creating a pretend database, or start up a local server, you can use the teardown block to set your system back to where it started
- Mocha's
after()andafterEach()hooks work exactly likebefore()andbeforeEach(), expect that they happen after - If you find yourself depending heavily on the teardown phase, you should double-check that you’re testing the right kind of function
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
other tests that run later.
0:00
That's why mocha provides a tear down
phase, to remove unwanted variables.
0:00
In addition, if your test changed
your development environment,
0:06
like creating a pretend database.
0:09
Or start up a local server,
0:11
you can use the tear down block to set
your system back to where it started.
0:13
You'll need tear downs more often when
your tests need a pretend database, or
0:19
they interact with the DOM somehow.
0:23
For example, you might be testing
a function that sets up a new remote
0:25
database, creates a local file or
starts a server instance.
0:29
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