class TestScope
A class that represents a test scope, containing a number of test cases.
class TestScope
Description
Test scopes are created using calls to describe(). The TestScope instance is passed to the definition function immediately, so it can use its own TestScope methods — for example to set callbacks that run before/after every test in the scope.
Example
describe("My test scope", (scope) => {
scope.beforeEach(() => {
// ... this runs before each test
});
test("My test case", () => {});
});
Static Members
- TestScope.getScope() staticReturns the current scope, if a describe() function is currently running.
- TestScope.getRunningTests() staticReturns a list of all currently running (sync and async) tests.
Instance Members
- scope readonlyThe containing scope, if any.
- name readonlyName of this scope.
- getResults()Returns the (current) results of all tests in this scope, and all nested scopes.
- setTimeout(timeoutMs)Sets a timeout for all tests in this scope, and nested scopes.
- beforeEach(f)Adds a callback that’s called before each test in this scope, and nested scopes.
- afterEach(f)Adds a callback that’s called after each test in this scope, and nested scopes.
- beforeAll(f)Sets a callback that’s called before the first test in this scope.
- afterAll(f)Sets a callback that’s called after the last test in this scope.
- addTest(name, f, exclusive?, initResult?)Adds a test to this scope (used by test()).
- addScope(name, f, parallel?, exclusive?)Adds a nested scope to this scope (used by describe()).
- runTestsAsync(timeout?)Runs all tests in this scope asynchronously (used by runTestsAsync()).