April 2018
Beginner
536 pages
13h 21m
English
A test suite is a group of test cases. We have already learned that we can use the describe function from Mocha to define a test suite and the it function to define a test case. However, we have not learned that we can define event handlers that can be invoked before and after all the tests in a test suite. The following code snippet demonstrates how we can define these event handlers:
describe("My test suite", () => {
before(() => {
// Invoked once before ALL tests
});
after(() => {
// Invoked once after ALL tests
});
beforeEach(() => {
// Invoked once before EACH test
});
afterEach(() => {
// Invoked once before EACH test
});
it(() => {
// Test case
});
});
This can be useful if we want to reuse some of the initialization ...