From ede310303b9893146bd7cc24261a50e3b47c633a Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Mon, 23 Oct 2017 19:53:26 -0700 Subject: [PATCH] add failing test for .visible bug --- test/visible.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/visible.js b/test/visible.js index 20f7ecb..5d53bce 100644 --- a/test/visible.js +++ b/test/visible.js @@ -22,3 +22,26 @@ test('visible: no output when level is too low', t => { t.is(ctx.visible.red('foo'), ''); t.is(ctx.red.visible('foo'), ''); }); + +test('test switching back and forth between enabled and disabled', t => { + const ctx = new m.constructor({level: 3, enabled: true}); + t.is(ctx.red('foo'), '\u001B[31mfoo\u001B[39m'); + t.is(ctx.visible.red('foo'), '\u001B[31mfoo\u001B[39m'); + t.is(ctx.red.visible('foo'), '\u001B[31mfoo\u001B[39m'); + t.is(ctx.visible('foo'), 'foo'); + t.is(ctx.red('foo'), '\u001B[31mfoo\u001B[39m'); + + ctx.enabled = false; + t.is(ctx.red('foo'), 'foo'); + t.is(ctx.visible('foo'), ''); + t.is(ctx.visible.red('foo'), ''); + t.is(ctx.red.visible('foo'), ''); + t.is(ctx.red('foo'), 'foo'); + + ctx.enabled = true; + t.is(ctx.red('foo'), '\u001B[31mfoo\u001B[39m'); + t.is(ctx.visible.red('foo'), '\u001B[31mfoo\u001B[39m'); + t.is(ctx.red.visible('foo'), '\u001B[31mfoo\u001B[39m'); + t.is(ctx.visible('foo'), 'foo'); + t.is(ctx.red('foo'), '\u001B[31mfoo\u001B[39m'); +});