A tool for testing console logs
Installation
with yarn
yarn add --dev consolemock
or with npm
npm install --save-dev consolemock
API
; console = ;
console;console;console;console;console;console;console;console;console;console;console;console;
console.history();
↳ LOG: 'a message' GROUP: 'a group' _INFO: 'maybe an object?' a: 'str' b: false c: 1 2 3 d: a: 'b' _WARN: 'something useful' _ERROR: 'something unexpected' _GROUP: '%c a nested group with styling' 'color: #1da1f2; font-weight: bold;' __LOG: '%c a nested log with styling' 'color: #D63230;' _LOG: 'almost done' INFO: '%c fin' 'font-weight: bold;' DEBUG: 'some debug statement'
console.printHistory();
↳ "LOG a message
GROUP a group
INFO maybe an object?, {a: 'str', b: false, c: [1, 2, 3], d: {a: 'b'}}
WARN something useful
ERROR something unexpected
GROUP %c a nested group with styling, color: #1da1f2; font-weight: bold;
LOG %c a nested log with styling, color: #D63230;
LOG almost done
INFO %c fin, font-weight: bold;
DEBUG some debug statement"
console.clearHistory()
↳ console;console; console; console; consolehistory // returns [{ LOG: ['apple'] }]
console.print(message, [message1, ..., messageN])
↳ Logs messages to the console when debugging. Provide makeConsoleMock
with the
native console
object when creating the mock:
; console = ;
Uses
consolemock
With Snapshot Testing
⚡ Use The output of printHistory
works great with
Jest's snapshot testing.
Create the mock console, log a few messages, then save the output of
printHistory
as a snapshot.