test
Adds a test case in the current scope.
test(name: string, f: (test: TestCase) => void | Promise<void>): void
Notes
- This function must be used within a function passed to describe().
- Test functions may be
async
, all promises are awaited automatically.
Parameters
- name — The name of the test
- f — The function that defines the test; if this function throws an error, the test fails automatically
Example
// define a simple test:
describe("Math", () => {
test("One plus one", () => {
expect(1 + 1).toBe(2);
});
});
Static Members
- function skip(name, f) staticAdds a test case that will be skipped.
- function todo(name, f?) staticAdds a test case that will be marked as ‘to do’.
- function only(name, f) staticAdds a test case that will be run exclusively.