🏛
Test Structure
How to write your tests
Tests can be grouped logically inside a describe() block.
1
describe("a set of tests", () => {
2
// put some tests in here
3
});
Copied!
Some tests can be nested in groups like this.
1
describe("a set of tests", () => {
2
// a nested group
3
describe("a nesting of tests", () => {
4
// put some tests in here
5
});
6
});
Copied!
Now, as-pect will logically group the nested tests within the top level group and the nested group.
The following top level functions are provided to you as units for test grouping.
1
/**
2
* Common practice for using the test() function is to name
3
* the test after the thing that is being tested.
4
*/
5
test("some noun or verb", () => {});
6
7
/**
8
* Common practice for using the it() function is to name it
9
* after a tested behavior.
10
*/
11
it("should do something as expected", () => {});
12
13
/**
14
* For tests that are incomplete and need review, or shouldn't
15
* run because they describe behavior that is not supported yet,
16
* use the xit() and xtest() function to have the module ignore
17
* that test.
18
*/
19
xtest("something that shouldn't run", () => {});
20
xit("shouldn't run", () => {});
21
22
/**
23
* In jest, you can check to see if a function throws an error
24
* by using the expect(func).toThrow() expectation. However, this
25
* can become tedious to write, and as-pect has a few functions
26
* that allow you to describe unreachable behavior with less code.
27
* Use the throws() and xthrows() function to describe a test that
28
* is expected to fail.
29
*
30
* Name your test after the condition that causes your test to error.
31
*/
32
throws("when it should throw", () => {});
33
itThrows("when it should throw", () => {});
34
35
/**
36
* For setup code that runs ONE time before a group is tested,
37
* use the beforeAll and afterAll function to run code once per group.
38
*/
39
beforeAll(() => {});
40
afterAll(() => {});
41
42
/**
43
* For setup code that runs every time before each test is tested,
44
* use the beforeEach and afterEach function to run code once per test.
45
*/
46
beforeEach(() => {});
47
afterEach(() => {});
Copied!
Jest supports nested tests, but this feature is currently unsupported by as-pect. However, this will be supported when 4.0.0 is released.
Copy link