{"id":13493705,"url":"https://github.com/ttmarek/consolemock","last_synced_at":"2025-03-28T12:32:17.886Z","repository":{"id":46934210,"uuid":"84371900","full_name":"ttmarek/consolemock","owner":"ttmarek","description":"A tool for testing console logs","archived":false,"fork":false,"pushed_at":"2022-12-07T09:43:48.000Z","size":498,"stargazers_count":101,"open_issues_count":17,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-24T13:44:45.444Z","etag":null,"topics":["javascript","javascript-library","jest","testing-tools"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ttmarek.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-08T22:24:47.000Z","updated_at":"2023-10-31T03:00:20.000Z","dependencies_parsed_at":"2023-01-24T16:31:28.860Z","dependency_job_id":null,"html_url":"https://github.com/ttmarek/consolemock","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttmarek%2Fconsolemock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttmarek%2Fconsolemock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttmarek%2Fconsolemock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ttmarek%2Fconsolemock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ttmarek","download_url":"https://codeload.github.com/ttmarek/consolemock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246030662,"owners_count":20712415,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","javascript-library","jest","testing-tools"],"created_at":"2024-07-31T19:01:17.965Z","updated_at":"2025-03-28T12:32:12.862Z","avatar_url":"https://github.com/ttmarek.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/ttmarek/consolemock\"\u003e\n    \u003cimg alt=\"consolemock\" src=\"https://raw.githubusercontent.com/ttmarek/consolemock/master/logo/logo.png\" width=\"500\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ci\u003eA tool for testing console logs\u003c/i\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/consolemock\"\u003e\u003cimg src=\"https://img.shields.io/npm/dy/consolemock.svg\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/consolemock\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/consolemock.svg\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/ttmarek/consolemock/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/github/license/ttmarek/consolemock.svg\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Installation\n\nwith yarn\n```\nyarn add --dev consolemock\n```\n\nor with npm\n```\nnpm install --save-dev consolemock\n```\n\n## API\n\n```js\nimport makeConsoleMock from 'consolemock';\n\nconsole = makeConsoleMock();\n```\n\n```js\nconsole.log('a message');\nconsole.group('a group');\nconsole.info('maybe an object?', { a: 'str', b: false, c: [1, 2, 3], d: { a: 'b' } });\nconsole.warn('something useful');\nconsole.error('something unexpected');\nconsole.group('%c a nested group with styling', 'color: #1da1f2; font-weight: bold;');\nconsole.log('%c a nested log with styling', 'color: #D63230;');\nconsole.groupEnd();\nconsole.log('almost done');\nconsole.groupEnd();\nconsole.info('%c fin', 'font-weight: bold;');\nconsole.debug('some debug statement');\n```\n\n### \u0026#x21b3; `console.history();`\n\n```js\n[\n  { LOG: ['a message'] },\n  { GROUP: ['a group'] },\n  { _INFO: ['maybe an object?', { a: 'str', b: false, c: [1, 2, 3], d: { a: 'b' } }] },\n  { _WARN: ['something useful'] },\n  { _ERROR: ['something unexpected'] },\n  { _GROUP: ['%c a nested group with styling', 'color: #1da1f2; font-weight: bold;'] },\n  { __LOG: ['%c a nested log with styling', 'color: #D63230;'] },\n  { _LOG: ['almost done'] },\n  { INFO: ['%c fin', 'font-weight: bold;'] },\n  { DEBUG: ['some debug statement'] }\n]\n```\n\n### \u0026#x21b3; `console.printHistory();`\n\n```\n\"LOG a message\nGROUP a group\n  INFO maybe an object?, {a: 'str', b: false, c: [1, 2, 3], d: {a: 'b'}}\n  WARN something useful\n  ERROR something unexpected\n  GROUP %c a nested group with styling, color: #1da1f2; font-weight: bold;\n    LOG %c a nested log with styling, color: #D63230;\n  LOG almost done\nINFO %c fin, font-weight: bold;\nDEBUG some debug statement\"\n```\n\n### \u0026#x21b3; `console.clearHistory()`\n\n```js\nconsole.log('hello');\nconsole.log('world');\n\nconsole.clearHistory();\n\nconsole.log('apple');\n\nconsole.history() // returns [{ LOG: ['apple'] }]\n```\n\n### \u0026#x21b3; `console.print(message, [message1, ..., messageN])`\n\nLogs messages to the console when debugging. Provide `makeConsoleMock` with the\nnative `console` object when creating the mock:\n\n```js\nimport makeConsoleMock from 'consolemock';\n\nconsole = makeConsoleMock(console);\n```\n\n## Uses\n\n### \u0026#x26A1; Use `consolemock` With Snapshot Testing\n\nThe output of `printHistory` works great with\n[Jest's snapshot testing](http://facebook.github.io/jest/docs/en/snapshot-testing.html#snapshot-testing-with-jest).\nCreate the mock console, log a few messages, then save the output of\n`printHistory` as a snapshot.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://cloud.githubusercontent.com/assets/7446702/24484314/93995c3a-14cb-11e7-9075-563d6e200a92.png\" width=\"650\"\u003e\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fttmarek%2Fconsolemock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fttmarek%2Fconsolemock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fttmarek%2Fconsolemock/lists"}