Skip to content

sodaru/jest-environment-steps

Repository files navigation

jest-environment-steps

Jest Environment to run the tests as Steps

Publish

npm i jest-environment-steps

Overview

In Jest, all tests within a test file run sequentially in the order of their appearance. But if a test fails, the next tests continue to execute.

For writing tests for a behavior, where each test depends on the success of the previous test, this built-in feature may cause unnecessary tests to run when a test fails.

Examples of behavior tests

  • Testing the CRUD APIs on a database.
    Writing the tests for Create, Read, Update, and Delete in the same sequence make it sense to test all APIs in the same order. When Create fails, there is no point in running tests for Read, Update, and Delete APIs

This library provides a jest environment to add new features to the way the tests are executed.

Inspired by Mocha Steps

Features

  • Runs all previous tests, before running the selected test when the testNamePattern argument is provided.
  • Skip all next tests, if a test fails

Install

npm i jest-environment-steps

Usage

An environment in jest can be applied using either of the below options.

  1. Set testEnvironment in jest.config.js to enable Steps for all tests

    // jest.config.js
    {
        "testEnvironment": "steps"
    }
  2. Use the docBlock to enable Steps for a specific file

    /**
    * @jest-environment steps
    */
    
    describe("Tests in this describe runs as steps", () => {
        ...
    })

For more configuration on using the environment in jest refer to Jest Config Doc

Assumptions

  • This Enables Steps on top of the node environment only

Support

This project is a part of the Open Source Initiative from Sodaru Technologies

Write an email to opensource@sodaru.com for queries on this project

About

Jest Environment to Enable Steps

Resources

License

Stars

Watchers

Forks

Packages

No packages published