Testing
Setting up Tests
Use ks.test() to configure tests.
ks.test({ title: Test Title, input: Value or Function or Error, etc., expect: Expected Value,});input
input can be a value, a function, an error, etc.
import Kensa from 'kensajs';import { testFunction } from './testFunction';
const ks = Kensa();
// Passing a valueks.test({ title: 'Test Item', input: 2, expect: 2,});
// Executing a function and passing its valueks.test({ title: 'Test Item', input: testFunction(1, 1), expect: 2,});
// Passing the function itselfks.test({ title: 'Test Item', input: () => { testFunction(1, 1) }, expect: 2,});
// Passing an asynchronous functionks.test({ title: 'Test Item', input: async () => { await testFunction(1, 1) }, expect: 2,});
// Passing an errorks.test({ title: 'Test Item', input: () => { throw new Error('error'); }, expect: new Error('error'),});
ks.run();実行結果
✓ Test Item✓ Test Item✓ Test Item✓ Test Item✓ Test Item
TOTAL: 5, PASS: 5, FAIL: 0