check-expect
check-expect is a simple unit testing framework for JavaScript development in a JavaScript package. check-expect is a mature, viable way to make your test-driven development drive the design of your data, and your data drive the design of your functions. It's also a simple tool that allows you to execute unit tests inline with your code, in a systematic way.
This is a fork of the original check-expect, hosted on GitHub and last updated in 2016.
Features
- Support for inline unit tests. check-expect will support test created in another directory as well.
- Support for TDD and DDD development.
- Support for Systematic Program Design methods using HtDD and HtDF recipes.
- Support for color coded terminal (console) output.
TODO
- GUI support.
Installation
-
Install check-expect.
npm install -g check-expect -
Now you can now add a reference to the check-expect package like so.
// import packagevar checkExpect = ; -
Write some code and test it using check-expect inline with your code.
// import packagesvar checkExpect = ;/* Usage and test modescheckExpect(function|object|type, mode, param, expected value, "a description of the test")checkExpect uses three Test Modes:- void_mode: for testing and designing algorithms with objects and primitive types- normal_mode: for testing and designing algorithms with primitive types- list_mode: for testing and designing algorithms with lists, objects and primitive typesA test mode must be passed as the second argument to the checkExpect() function*/var void_mode = 0;var normal_mode = 1;var list_mode = 2;// define a function{ // could replace return statement withreturn a * a; // lambda statement: a => Math.pow(a,2)} // from code_statement_B below.// examplesvar num_to_square = 12;var code_statement_A = 12 * 12; // used in the function body// check the algorithm design of our square function, and unit test it at the same time;// Or just pass our examples;// Or use lambda expressionsvar Math;;// Or use JSON objects tested in void_modevar Person =firstName:"John"lastName: "Doe"{return thisfirstName + " " + thislastName;};;// Or use in testing functions that consume a list and produce a stringvar str1 = "Darel";var str2 = "Johnson";var param3 = "Darel" "Johnson";{var newStr = ""str =numArgs = argumentslength;forvar i = 0; i < numArgs; i++str = argumentsi;newStr += str +" ";return newStr;}// should produce "Darel Johnson"; -
Execute your JavaScript from the command line (terminal) to see the unit test results. Most tests usually fail (RED) in the beginning.
-
Refactor your code and execute your script until all functions under test, turn GREEN.
-
That's it! You're done.
Upgrades
-
Upgrade check-expect.
npm update -g check-expect
That command will upgrade an existing installation of check-expect.
Configuration
None - No configuration needed.
Support
For check-expect support contact me at dareljohnson@yahoo.com
Project Issues
Report a bug at https://github.com/dareljohnson/check-expect/issues
License
This project originally started life as JavaScript unit test project. This project was abandoned in 2013 and was brought back to life as check-expect by our team in 2016. In the process, most of the project was refactored and brought up to speed with modern python best practices. The work done prior to the 2013 rewrite is licensed under MIT. Improvements since then are licensed under MIT. See LICENSE for more details.
SemVer
This project implements Semantic Versioning.
Credits
- Darel Johnson https://github.com/dareljohnson