@cainiaofe/cn-ui-m
Version:
56 lines (55 loc) • 2.3 kB
JavaScript
import { getFormattedValue } from '../get-formatted-value';
import { renderHook } from '@testing-library/react-hooks';
describe('getFormattedValue', function () {
it('should return formatted value with innerAfter', function () {
var inputValue = 10;
var format = function (value) { return "Formatted ".concat(value); };
var innerAfter = ' units';
var label = 'Value: ';
var result = renderHook(function () {
return getFormattedValue(inputValue, format, innerAfter, label);
}).result;
expect(result.current).toBe('Value: Formatted 10 units');
});
it('should return formatted value without innerAfter', function () {
var inputValue = 5;
var format = function (value) { return "Formatted ".concat(value); };
var innerAfter = '';
var label = 'Value: ';
var result = renderHook(function () {
return getFormattedValue(inputValue, format, innerAfter, label);
}).result;
expect(result.current).toBe('Value: Formatted 5');
});
it('should return unformatted value with innerAfter', function () {
var inputValue = 20;
var format = undefined;
var innerAfter = ' units';
var label = 'Value: ';
var result = renderHook(function () {
return getFormattedValue(inputValue, format, innerAfter, label);
}).result;
expect(result.current).toBe('Value: 20 units');
});
it('should return unformatted value without innerAfter', function () {
var inputValue = 15;
var format = undefined;
var innerAfter = '';
var label = 'Value: ';
var result = renderHook(function () {
return getFormattedValue(inputValue, format, innerAfter, label);
}).result;
expect(result.current).toBe('Value: 15');
});
it('should return unformatted value with string format', function () {
var inputValue = 15;
var format = 'Formatted';
var innerAfter = '';
var label = 'Value: ';
var result = renderHook(function () {
// @ts-ignore
return getFormattedValue(inputValue, format, innerAfter, label);
}).result;
expect(result.current).toBe('Value: 15');
});
});