๐Ÿ› Test Structure

How to write your tests

Tests can be grouped logically inside a describe() block.

describe("a set of tests", () => {
// put some tests in here
});

Some tests can be nested in groups like this.

describe("a set of tests", () => {
// a nested group
describe("a nesting of tests", () => {
// put some tests in here
});
});

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.

/**
* Common practice for using the test() function is to name
* the test after the thing that is being tested.
*/
test("some noun or verb", () => {});
โ€‹
/**
* Common practice for using the it() function is to name it
* after a tested behavior.
*/
it("should do something as expected", () => {});
โ€‹
/**
* For tests that are incomplete and need review, or shouldn't
* run because they describe behavior that is not supported yet,
* use the xit() and xtest() function to have the module ignore
* that test.
*/
xtest("something that shouldn't run", () => {});
xit("shouldn't run", () => {});
โ€‹
/**
* In jest, you can check to see if a function throws an error
* by using the expect(func).toThrow() expectation. However, this
* can become tedious to write, and as-pect has a few functions
* that allow you to describe unreachable behavior with less code.
* Use the throws() and xthrows() function to describe a test that
* is expected to fail.
*
* Name your test after the condition that causes your test to error.
*/
throws("when it should throw", () => {});
itThrows("when it should throw", () => {});
โ€‹
/**
* For setup code that runs ONE time before a group is tested,
* use the beforeAll and afterAll function to run code once per group.
*/
beforeAll(() => {});
afterAll(() => {});
/**
* For setup code that runs every time before each test is tested,
* use the beforeEach and afterEach function to run code once per test.
*/
beforeEach(() => {});
afterEach(() => {});

Jest supports nested tests, but this feature is currently unsupported by as-pect. However, this will be supported when 4.0.0 is released.