chalk/test/enabled.js

36 lines
835 B
JavaScript
Raw Normal View History

2017-07-23 22:17:33 +02:00
import test from 'ava';
// Spoof supports-color
require('./_supports-color')(__dirname);
2018-09-18 14:05:08 +07:00
const chalk = require('..');
2017-07-23 22:17:33 +02:00
test('don\'t output colors when manually disabled', t => {
2018-09-18 14:05:08 +07:00
chalk.enabled = false;
t.is(chalk.red('foo'), 'foo');
chalk.enabled = true;
2017-07-23 22:17:33 +02:00
});
test('enable/disable colors based on overall chalk enabled property, not individual instances', t => {
2018-09-18 14:05:08 +07:00
chalk.enabled = false;
const {red} = chalk;
2017-07-23 22:17:33 +02:00
t.false(red.enabled);
2018-09-18 14:05:08 +07:00
chalk.enabled = true;
2017-07-23 22:17:33 +02:00
t.true(red.enabled);
2018-09-18 14:05:08 +07:00
chalk.enabled = true;
2017-07-23 22:17:33 +02:00
});
test('propagate enable/disable changes from child colors', t => {
2018-09-18 14:05:08 +07:00
chalk.enabled = false;
const {red} = chalk;
2017-07-23 22:17:33 +02:00
t.false(red.enabled);
2018-09-18 14:05:08 +07:00
t.false(chalk.enabled);
2017-07-23 22:17:33 +02:00
red.enabled = true;
t.true(red.enabled);
2018-09-18 14:05:08 +07:00
t.true(chalk.enabled);
chalk.enabled = false;
2017-07-23 22:17:33 +02:00
t.false(red.enabled);
2018-09-18 14:05:08 +07:00
t.false(chalk.enabled);
chalk.enabled = true;
2017-07-23 22:17:33 +02:00
});