chalk/test/instance.js

25 lines
702 B
JavaScript
Raw Normal View History

import test from 'ava';
2021-04-18 00:33:03 +12:00
import chalk, {Chalk} from '../source/index.js';
2021-04-16 15:23:29 +07:00
chalk.level = 1;
test('create an isolated context where colors can be disabled (by level)', t => {
2021-04-18 00:33:03 +12:00
const instance = new Chalk({level: 0});
t.is(instance.red('foo'), 'foo');
t.is(chalk.red('foo'), '\u001B[31mfoo\u001B[39m');
instance.level = 2;
t.is(instance.red('foo'), '\u001B[31mfoo\u001B[39m');
});
test('the `level` option should be a number from 0 to 3', t => {
/* eslint-disable no-new */
t.throws(() => {
2021-04-18 00:33:03 +12:00
new Chalk({level: 10});
2020-10-04 10:56:24 +13:00
}, {message: /should be an integer from 0 to 3/});
t.throws(() => {
2021-04-18 00:33:03 +12:00
new Chalk({level: -1});
2020-10-04 10:56:24 +13:00
}, {message: /should be an integer from 0 to 3/});
/* eslint-enable no-new */
});