tefra
v0.5.1
Published
Regular old javascript test framework
Readme
Tefra - a basic test framework
A small project for practice writing cleaner code and more structured architecture.
Installation
npm install tefraAdd to your package.json:
{
"scripts": {
"test": "tefra"
}
}Run from command line:
npm test [optional test path] [optional excluded file or folder]Features
Basic asserter
equal(actual, expected); // Deep equality
is(actual, expected); // Reference equality
throwsError(func, expectedError, ...args) // Error assertionBasic test runner
describe(groupName, groupFunction);
test(specName, specFunction);
beforeEach(setupFunction);
afterEach(teardownFunction);Usage
- Create a file ending with .test.js
- Import file under test
- Describe the test
- Assert the test
- Run tests
Example
echoer.test.js
import echoer from './echoer.js';
describe('testBlockOuter', () => {
describe('testBlock', () => {
let setup = 1;
let teardown = 1;
beforeEach(() => {
setup = 0
});
afterEach(() => {
teardown = null;
});
test('should pass - return same value as argument', () => {
equal(echoer.echo('t1'), 't1');
});
test('should fail', () => {
equal(echoer.echo('t1'), 't2');
});
test('should catch error', () => {
throwsError(echoer.errFunc, new Error('bad'), 't1');
});
});
});Config
Disable logging to console:
setLogToConsole(false);Async support
Currently does not support asynchronous operations.
Warning
This is an experimental low priority project. Maintenance not scheduled. Should not be used in production.
