Skip to content

romedu/create-test-cases

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

create-test-cases

travis-build npm-version npm-license

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 } = require("create-test-cases");

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 } = 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);

License

MIT

About

A faster and easier way to create test cases

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published