Add tests

This commit is contained in:
Tom Sherman 2019-01-26 21:53:23 +00:00
parent 08f9e5f3e3
commit 6768476575
7 changed files with 82 additions and 67 deletions

34
test/instance.js Normal file
View file

@ -0,0 +1,34 @@
import test from 'ava';
// Spoof supports-color
require('./_supports-color')(__dirname);
const chalk = require('..');
test('create an isolated context where colors can be disabled (by level)', t => {
const instance = new chalk.instance({level: 0, enabled: true});
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('create an isolated context where colors can be disabled (by enabled flag)', t => {
const instance = new chalk.instance({enabled: false});
t.is(instance.red('foo'), 'foo');
t.is(chalk.red('foo'), '\u001B[31mfoo\u001B[39m');
instance.enabled = true;
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(() => {
new chalk.instance({level: 10});
}, /should be an integer from 0 to 3/);
t.throws(() => {
new chalk.instance({level: -1});
}, /should be an integer from 0 to 3/);
/* eslint-enable no-new */
});