Test-Builder
A node.js library made to test the latest build of your amazing APIs.
This library is made to be as simple as possible, to get your tests completed in style. To do this, Test-Build has built in styles using chalk template litterals such as green.bold.underline
. You can read more about those types of litterals on chalk's npm readme.
Getting Started:
Instalation:
npm install test-builder
Setup
Creating an instance:
/*
Import the required class to make a test.
Test class is the constructor to create test instances.
*/
const { Test } = require('test-builder');
/*
Import the api or to test using test-builder.
*/
const someAPI = require('path/to/some/api');
let ApiTest = new Test(
'someAPI', // Sets the name of the test, shown in the first scope label.
true, // Determines if values are shown in the detail.
theme // The theme configuration determining the layout of the output. See 'Themes'.
);
ApiTest.test(
true, // Detail, same as in the Test class, but overrides the parent.
'Random-Emoji', // Name of the sub-test displayed in the second scope.
'A random emoji api.' // The description displayed after 'failure' or 'success' in the console.
).notEqual( // Function to test if two or more values are not all the same.
someAPI.randomEmote(), // Get random emote from some api.
someAPI.randomEmote() // Get another random emote.
);
/*
The test would have tested if the emotes are random, which means there is only a small test of being equal.
*/
ApiTest.test(
true, // Detail, same as in the Test class, but overrides the parent.
'Alphabet', // Name of the sub-test displayed in the second scope.
'Get first letter of alphabet.' // The description displayed after 'failure' or 'success' in the console.
).equals( // Function to test if two or more values are equivelent.
someAPI.nthOfAlphabet(1), // Get 1st letter of the alphabet, in this example it is supposed to be 1 for first.
'a' // First letter of the alphabet
);
/*
In this example, 'someAPI.nthOfAlphabet' was 0-based instead of starting at one, causing it to fail the test.
*/
The above code would yield a result simmilar to the one below, results may differ for theme and api.
Test Functions
const { Test } = require('test-builder');
let test = new Test().test(); // The test instance with the test functions.
/*
Tests if all values supplied in the arguments are equivelent.
*/
test.equals(value[,value...])
/*
Tests if the arguments supplied are not all the same.
*/
test.notEqual(value[,value...])
/*
Tests if all values supplied in the arguments are of the same type.
(from `typeof value`)
*/
test.sameType(value[,value...])
/*
Tests if the types of the values in the arguments are not all equivelent.
(from `typeof value`)
*/
test.notEqual(value[,value...])