3.4.1 • Published 11 months ago

@wezom/toolkit-jest v3.4.1

Weekly downloads
24
License
BSD-3-Clause
Repository
github
Last release
11 months ago

@wezom/toolkit-jest

Test Build

Useful tools for working with Jest

StatementsBranchesFunctionsLines
StatementsBranchesFunctionsLines

Table of Content:

  1. Usage
  2. Tools
    1. jestFunctionSignatureTest()
    2. jestLogMute() and jestLogUnmute()
  3. Contributing
  4. License

Usage

Install npm package

npm i @wezom/toolkit-jest

▲ Go Top | ▲ Table of Content


Tools

jestFunctionSignatureTest()

comment: <> (AUTODOC-TOOL-START::function-signature-test#default)

Function signature test with set of custom cases

Parameters:

NameData typeArgumentDefault valueDescription
methodT
casesFunctionSignatureTestCase<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
		}
	]);
});

comment: <> (AUTODOC-TOOL-END)


▲ Go Top | ▲ Table of Content


jestLogMute() and jestLogUnmute()

comment: <> (AUTODOC-TOOL-START::log-mute#jestLogMute)

Mute default console.log logging

Parameters:

NameData typeArgumentDefault valueDescription
methodMethodTypeoptional'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();
});

comment: <> (AUTODOC-TOOL-END)


▲ Go Top | ▲ Table of Content


Contributing

Please fill free to create issues or send PR

Licence

BSD-3-Clause License


3.4.0

11 months ago

3.4.1

11 months ago

3.3.2

2 years ago

3.3.0

3 years ago

3.2.1

3 years ago

3.2.0

3 years ago

3.1.1

3 years ago

3.1.0

3 years ago

3.0.0

3 years ago

2.0.0

3 years ago

1.2.0-beta.0

3 years ago

1.1.0-beta.0

3 years ago

1.0.1-beta.0

3 years ago