create-test-cases
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.
Installation
$ npm install create-test-cases
API
const createTestCases TestCase = ;
createTestCases(testData, fnToTest)
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.
testData
The testData parameter is an array of TestCase instance objects.
fnToTest
Function in which the test cases will be based.
TestCase(inputs, expectedOutput, matchers, testName)
Will create an instance of the TestCase "class".
Note: Calling the function with the new
keyword is not required.
inputs
Array of parameters to be passed to the currently testing function
expectedOutput
Expected return value from the currently testing function
matchers
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.
testName
String to be used as the name of the test. Default: "should return " + expectedOutput
.
Examples
This example demonstrates how to create test cases using the createTestCases function.
const createTestCases TestCase = ;const testData = true true "toBe" false true "not" "toBe" "Hello" "Hello"; const testFunction = input; ;