While this answer just shows the documentation notes again, and had some comments to try to help show the difference, the answer below by @tomasz-wszelaki should be refered to.
Mocha’s test runner explains this functionality the best in the Hooks section of the Mocha Test Runner.
From the Hooks section:
describe('hooks', function() {
before(function() {
// runs before all tests in this file regardless where this line is defined.
});
after(function() {
// runs after all tests in this file
});
beforeEach(function() {
// runs before each test in this block
});
afterEach(function() {
// runs after each test in this block
});
// test cases
});
You can nest these routines within other describe blocks which can also have before/beforeEach routines.