Skip to content

Commit

Permalink
add test for enable/disable of existing instances
Browse files Browse the repository at this point in the history
  • Loading branch information
Qix- committed Sep 19, 2020
1 parent 22e13fe commit 27152ca
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,24 @@ describe('debug', () => {
assert.deepStrictEqual(oldNames.map(String), debug.names.map(String));
assert.deepStrictEqual(oldSkips.map(String), debug.skips.map(String));
});

it('handles re-enabling existing instances', () => {
debug.disable('*');
const inst = debug('foo');
const messages = [];
inst.log = msg => messages.push(msg.replace(/^[^@]*@([^@]+)@.*$/, '$1'));

inst('@test@');
assert.deepStrictEqual(messages, []);
debug.enable('foo');
assert.deepStrictEqual(messages, []);
inst('@test2@');
assert.deepStrictEqual(messages, ['test2']);
inst('@test3@');
assert.deepStrictEqual(messages, ['test2', 'test3']);
debug.disable('*');
inst('@test4@');
assert.deepStrictEqual(messages, ['test2', 'test3']);
});
});
});

0 comments on commit 27152ca

Please sign in to comment.