You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 16, 2026. It is now read-only.
We learned about the four main phases of a test: setup, execute, verify and teardown. In the last exercise, you may have notice that the setup and teardown steps were identical between tests.
While execution and verification are unique to each test, setup and teardown are often similar or even identical for multiple tests within a test suite. The Mocha test framework provides functions that enable us to reduce repetition, simplify the scope of each test, and more finely control the execution of our test.
These functions (also referred as hooks) are:
beforeEach(callback) - callback is run before each test
afterEach(callback) - callback is run after each test
before(callback) - callback is run before the first test
after(callback) - callback is run after the last test
Each hook accepts a callback to be executed at various times during a test. The before ... hooks naturally happen before tests and are useful for separating out the setup steps of your tests. Meanwhile, the after ... hooks are executed after tests and are useful for separating out the teardown steps of your test.
We learned about the four main phases of a test: setup, execute, verify and teardown. In the last exercise, you may have notice that the setup and teardown steps were identical between tests.
While execution and verification are unique to each test, setup and teardown are often similar or even identical for multiple tests within a test suite. The Mocha test framework provides functions that enable us to reduce repetition, simplify the scope of each test, and more finely control the execution of our test.
These functions (also referred as hooks) are:
Each hook accepts a callback to be executed at various times during a test. The before ... hooks naturally happen before tests and are useful for separating out the setup steps of your tests. Meanwhile, the after ... hooks are executed after tests and are useful for separating out the teardown steps of your test.