node/test/parallel/test-util-styletext.js
Rafael Gonzaga 88e08bbe80 util: add styleText API to text formatting
Co-Authored-By: Hemanth HM <hemanth.hm@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/51850
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Adrian Estrada <edsadr@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
2024-02-27 12:10:14 +01:00

35 lines
624 B
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const util = require('util');
[
undefined,
null,
false,
5n,
5,
Symbol(),
() => {},
{},
[],
].forEach((invalidOption) => {
assert.throws(() => {
util.styleText(invalidOption, 'test');
}, {
code: 'ERR_INVALID_ARG_VALUE',
});
assert.throws(() => {
util.styleText('red', invalidOption);
}, {
code: 'ERR_INVALID_ARG_TYPE'
});
});
assert.throws(() => {
util.styleText('invalid', 'text');
}, {
code: 'ERR_INVALID_ARG_VALUE',
});
assert.strictEqual(util.styleText('red', 'test'), '\u001b[31mtest\u001b[39m');