jsunittests
Version:
A quick way to make unittests for your code
63 lines (42 loc) • 1.41 kB
Markdown
A lightweight JavaScript unit testing library that provides a quick and simple way to write and run unit tests for your code.
```bash
npm install unittests
```
```javascript
import { run_tests } from 'unittests';
// Define your test cases as arrays of [input, expected_output]
const examples = [
['test input 1', 'expected output 1'],
['test input 2', 'expected output 2']
];
// Your function to test
function myFunction(input) {
// Your implementation
return input;
}
// Run the tests
const results = run_tests(examples, myFunction);
// Print the results
results.print_results();
```
- Simple and lightweight testing framework
- Easy to write test cases using input/output pairs
- Clear test results output
- Percentage-based test success reporting
- Option to show/hide successful test cases
Runs the test cases and returns a TestResults object.
- `examples`: Array of test cases, where each test case is an array containing [input, expected_output]
- `func`: The function to test
Class that handles test results and reporting.
- `print_results(show_succeeded = false)`: Prints the test results
- `show_succeeded`: Optional boolean to show successful test cases (default: false)
## License
ISC