@wezom/toolkit-jest
v3.4.1
Published
Useful tools for working with Jest
Downloads
359
Maintainers
Readme
@wezom/toolkit-jest
Useful tools for working with Jest
| Statements | Branches | Functions | Lines | | --------------------------------------------------------------------------- | ---------------------------------------------------------------- | -------------------------------------------------------------------------- | ---------------------------------------------------------------------- | | | | | |
Table of Content:
Usage
Install npm package
npm i @wezom/toolkit-jest
Tools
jestFunctionSignatureTest()
Function signature test with set of custom cases
Parameters:
| Name | Data type | Argument | Default value | Description |
| ------ | -------------------------------- | -------- | ------------- | ----------- |
| method | T
| | |
| cases | FunctionSignatureTestCase<T>[]
| | |
Returns: void
Examples:
// some-function.ts
export const someFunction = (y: boolean, z: number, w: number): number | null =>
y ? z + w : null;
// some-function.spec.ts
import { someFunction } from 'some-function';
import { jestFunctionSignatureTest } from '@wezom/toolkit-jest';
describe('Function signature should match specification', () => {
jestFunctionSignatureTest(someFunction, [
{
parameters: [true, 4, 5],
expected: 9
},
{
name: 'Custom test name',
parameters: [false, 4, 5],
expected: null
},
{
name: 'Invoke parameters by function',
parameters: () => {
// some logic for generate params
return [...params];
},
expected: null
}
]);
});
jestLogMute() and jestLogUnmute()
Mute default console.log
logging
Parameters:
| Name | Data type | Argument | Default value | Description |
| ------ | ------------ | ---------- | ------------- | ----------- |
| method | MethodType
| optional | 'log'
|
Returns: void
Examples:
// some-function.ts
export const someFunction = (x: number, y: number): number => {
console.log('SOME LOG MESSAGE');
return x + y;
};
// some-function.spec.ts
import { someFunction } from 'some-function';
import { jestLogMute, jestLogUnmute } from '@wezom/toolkit-jest';
describe('Should be silent test', () => {
jestLogMute();
test('silent testing of the `someFunction`', () => {
expect(someFunction(1, 2)).toBe(3);
});
jestLogUnmute();
});
Contributing
Please fill free to create issues or send PR