yajstf is a very lightweight testing framework that is incredibly fast to get started with.
If you are curious about how to write a testing framework, take a peek into the code and if you want to borrow any source code just take a look at the terms and conditions in the License.
Install yajstf using npm
:
npm install --save-dev yajstf
Or yarn
:
yarn add --dev yajstf
Let's get started by writing a test for a hypothetical function that adds two numbers. First, create a sum.js
file:
function sum(a, b) {
return a + b;
}
module.exports = sum;
Then, create a file named sum.test.js
. This will contain our actual test:
const assert = require('assert');
const { sum } = require('../index');
test('adds 1 + 2 to equal 3', () => {
assert.strictEqual(sum(1, 2), 3);
});
Add the following section to your package.json
:
{
"scripts": {
"test": "jtf"
}
}
Finally, run npm run test
or yarn test
and yajstf will print this message:
✓ TEST - adds 1 + 2 to equal 3 - PASSED
You just successfully wrote your first test using yajstf!
This test used assert
and strictEqual
to test that two values were exactly identical.
You can run yajstf directly from the CLI (if it's globally available in your PATH
, e.g. by npm install yajstf --global
) or yarn global add yajstf
.
yajstf is WTFPL licensed.