test-flat
A test framework extension to support resources teardown and cleanup in flat tests.
Motivation
Writing flat (shallow) test suites has a number of advantages. However, testing frameworks rarely support before
/after
hooks as a part of an individual test. Such support would allow to create and clean up resources necessary for a single test suite, without having to rely on beforeEach
/afterEach
global hooks.
Getting started
Install
$ npm install test-flat --save-dev
Extend Jest
// jest.setup.js
Example
Here's an example of a flat test suite that tears down a Puppeteer browser and cleans up afterwards as a part of a single test suite:
test
Both
test.only.flat
andtest.skip.flat
are supported.
API
title
A test suite title.
suite
A test suite itself.
Test suite function in
test-flat
is always an asynchronous function and does not support thedone
callback argument.
before
An optional teardown hook to create any resources necessary for the respective test. Anything returned from this hook will be available as the context
argument in the suite
and after
functions.
after
An optional cleanup hook executed after the test is finished (passed or failed). Accepts an optional context
argument to clean up the resources created as a part of the before
hook.