Node.js function that creates test cases based on the specified inputs and outputs. Decrease the time taken to write simple test cases using this framework agnostic function.
Note This tool expects that the testing framework in use follows the common conventions.
$ npm install create-test-cases
const { createTestCases, TestCase } = require("create-test-cases");
Will create a describe blocks specifying all of the parameters passed to the function, and an it block for each of the test cases displaying the expected return value. Note: It is advised to call the function inside of a describe block.
The testData parameter is an array of TestCase instance objects.
Function in which the test cases will be based.
Will create an instance of the TestCase "class".
Note: Calling the function with the new
keyword is not required.
Array of parameters to be passed to the currently testing function
Expected return value from the currently testing function
Array of matchers to be used in the test case. Default: ["toBe"]
.
Note: Check your framework's documentation to see a list of the valid matchers.
String to be used as the name of the test. Default: "should return " + expectedOutput
.
This example demonstrates how to create test cases using the createTestCases function.
const { createTestCases, TestCase } = require("create-test-cases");
const testData = [
new TestCase([true], true, ["toBe"]),
new TestCase([false], true, ["not", "toBe"]),
new TestCase(["Hello"], "Hello")
];
const testFunction = input => input;
createTestCases(testData, testFunction);