{"id":16882736,"url":"https://github.com/alhadis/mocha-when","last_synced_at":"2026-05-07T04:37:43.526Z","repository":{"id":57299976,"uuid":"173745932","full_name":"Alhadis/Mocha-When","owner":"Alhadis","description":"Write BDD-style tests with improved clarity and eloquence.","archived":false,"fork":false,"pushed_at":"2019-07-06T16:41:56.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-06T20:34:54.372Z","etag":null,"topics":["bdd","literate-testing","mocha","zero-config"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/mocha-when","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Alhadis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-04T13:03:00.000Z","updated_at":"2019-10-20T12:33:48.000Z","dependencies_parsed_at":"2022-09-07T12:13:05.857Z","dependency_job_id":null,"html_url":"https://github.com/Alhadis/Mocha-When","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alhadis%2FMocha-When","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alhadis%2FMocha-When/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alhadis%2FMocha-When/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alhadis%2FMocha-When/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Alhadis","download_url":"https://codeload.github.com/Alhadis/Mocha-When/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244554402,"owners_count":20471216,"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":["bdd","literate-testing","mocha","zero-config"],"created_at":"2024-10-13T16:08:31.702Z","updated_at":"2025-10-06T06:31:38.912Z","avatar_url":"https://github.com/Alhadis.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status: TravisCI](https://travis-ci.org/Alhadis/Mocha-When.svg?branch=master)](https://travis-ci.org/Alhadis/Mocha-When)\n[![Latest package version](https://img.shields.io/npm/v/mocha-when.svg?colorB=brightgreen)](https://github.com/Alhadis/Mocha-When/releases/latest)\n\n“What's this?”\n--------------\nThis is a drop-in enhancement for [Mocha's BDD interface](https://mochajs.org/#bdd),\nwhich adds two small but tangible improvements:\n\n\n\u003ca name=\"when\"\u003e\u003c/a\u003e\n### A `when()` global\nThis is the same calling `describe()`, but the description you give is automatically prefixed by `\"When \"`:\n\n~~~js\nwhen(\"this test is run\", () =\u003e {\n\tit('gets prepended with the word \"When\"', …);\n});\n~~~\n\nWhich is a shorter, clearer way of writing:\n\n~~~js\ndescribe(\"when this test is run\", () =\u003e …);\n~~~\n\n\n\u003ca name=\"it\"\u003e\u003c/a\u003e\n### Tests specified by `it()` actually start with `\"It \"`\nMocha makes idiomatic tests fun to write ...\n\n~~~js\ndescribe(\"when the app starts\", () =\u003e {\n\tit(\"activates successfully\", () =\u003e …);\n\tit(\"connects to the server\", () =\u003e …);\n\tit(\"receives a valid payload\", () =\u003e …);\n});\n~~~\n\n... but not as fun to read:\n\n\twhen the app starts\n\t  ✓ activates successfully\n\t  ✓ connects to the server\n\t  ✓ receives a valid payload\n\t  ✓ displays the result\n\nThis module fixes such broken language by automatically prefixing each test:\n\n\twhen the app starts\n\t  ✓ it activates successfully\n\t  ✓ it connects to the server\n\t  ✓ it receives a valid payload\n\t  ✓ it displays the result\n\nIf a test (or suite) description already includes the expected prefix, it won't be modified.\nSo you needn't worry about stuff like this:\n\n\twhen When the prefix is included\n\t  ✓ it it won't repeat the word \"it\"\n\t  ✓ it it'll check for contractions too\n\n\n\nUsage\n-----\n1.\tAdd `mocha-when` to your project's dependencies:\n\t~~~sh\n\t# Using NPM:\n\tnpm install --save-dev mocha-when\n\n\t# Or with Yarn:\n\tyarn add mocha-when\n\t~~~\n\n2.\tActivate it by calling the function it exports:\n\t~~~js\n\trequire(\"mocha-when\")();\n\t~~~\n\tOr simply pass `mocha-when/register` to [Mocha's `require` option](https://mochajs.org/#-require-module-r-module):\n\t~~~js\n\t// In your `.mocharc.js` file:\n\tmodule.exports = {\n\t\trequire: [\n\t\t\t\"mocha-when/register\",\n\t\t]\n\t};\n\t~~~\n\n\nCaveats\n-------\n* ESLint won't recognise the `when()` global, so add it to your [`globals` list](https://eslint.org/docs/user-guide/configuring#specifying-globals).\n* Mocha's [`ui`](https://mochajs.org/#-ui-name-u-name) option is assumed to be `bdd` (the default).\n* Tests can be declared without an `it` prefix using `specify()`.\n* The enhancements applied by this module are persistent and irrevocable.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falhadis%2Fmocha-when","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falhadis%2Fmocha-when","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falhadis%2Fmocha-when/lists"}