{"id":14969357,"url":"https://github.com/iensu/mocha-cakes-2","last_synced_at":"2025-10-26T07:31:23.686Z","repository":{"id":57299764,"uuid":"51789996","full_name":"iensu/mocha-cakes-2","owner":"iensu","description":"A BDD plugin for Mocha testing framework","archived":false,"fork":false,"pushed_at":"2018-03-27T15:50:16.000Z","size":435,"stargazers_count":43,"open_issues_count":5,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-31T16:53:37.612Z","etag":null,"topics":["bdd","cucumber","gherkin","javascript","mocha","mocha-cakes","nodejs","tdd","testing","typescript"],"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/iensu.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":"2016-02-15T22:22:04.000Z","updated_at":"2022-11-02T03:05:41.000Z","dependencies_parsed_at":"2022-08-26T17:01:07.374Z","dependency_job_id":null,"html_url":"https://github.com/iensu/mocha-cakes-2","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iensu%2Fmocha-cakes-2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iensu%2Fmocha-cakes-2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iensu%2Fmocha-cakes-2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iensu%2Fmocha-cakes-2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iensu","download_url":"https://codeload.github.com/iensu/mocha-cakes-2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238284884,"owners_count":19446747,"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","cucumber","gherkin","javascript","mocha","mocha-cakes","nodejs","tdd","testing","typescript"],"created_at":"2024-09-24T13:41:44.546Z","updated_at":"2025-10-26T07:31:23.305Z","avatar_url":"https://github.com/iensu.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mocha Cakes 2\n\nMocha Cakes is a [Gherkin](https://github.com/cucumber/cucumber/wiki/Gherkin)/[Cucumber](https://cucumber.io/) syntax integration for the [Mocha](https://mochajs.org/) testing framework.\n\n[![Build Status](https://travis-ci.org/iensu/mocha-cakes-2.svg?branch=master)](https://travis-ci.org/iensu/mocha-cakes-2)\n[![Sponsored](https://img.shields.io/badge/chilicorn-sponsored-brightgreen.svg?logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAAA4AAAAPCAMAAADjyg5GAAABqlBMVEUAAAAzmTM3pEn%2FSTGhVSY4ZD43STdOXk5lSGAyhz41iz8xkz2HUCWFFhTFFRUzZDvbIB00Zzoyfj9zlHY0ZzmMfY0ydT0zjj92l3qjeR3dNSkoZp4ykEAzjT8ylUBlgj0yiT0ymECkwKjWqAyjuqcghpUykD%2BUQCKoQyAHb%2BgylkAyl0EynkEzmkA0mUA3mj86oUg7oUo8n0k%2FS%2Bw%2Fo0xBnE5BpU9Br0ZKo1ZLmFZOjEhesGljuzllqW50tH14aS14qm17mX9%2Bx4GAgUCEx02JySqOvpSXvI%2BYvp2orqmpzeGrQh%2Bsr6yssa2ttK6v0bKxMBy01bm4zLu5yry7yb29x77BzMPCxsLEzMXFxsXGx8fI3PLJ08vKysrKy8rL2s3MzczOH8LR0dHW19bX19fZ2dna2trc3Nzd3d3d3t3f39%2FgtZTg4ODi4uLj4%2BPlGxLl5eXm5ubnRzPn5%2Bfo6Ojp6enqfmzq6urr6%2Bvt7e3t7u3uDwvugwbu7u7v6Obv8fDz8%2FP09PT2igP29vb4%2BPj6y376%2Bu%2F7%2Bfv9%2Ff39%2Fv3%2BkAH%2FAwf%2FtwD%2F9wCyh1KfAAAAKXRSTlMABQ4VGykqLjVCTVNgdXuHj5Kaq62vt77ExNPX2%2Bju8vX6%2Bvr7%2FP7%2B%2FiiUMfUAAADTSURBVAjXBcFRTsIwHAfgX%2FtvOyjdYDUsRkFjTIwkPvjiOTyX9%2FAIJt7BF570BopEdHOOstHS%2BX0s439RGwnfuB5gSFOZAgDqjQOBivtGkCc7j%2B2e8XNzefWSu%2BsZUD1QfoTq0y6mZsUSvIkRoGYnHu6Yc63pDCjiSNE2kYLdCUAWVmK4zsxzO%2BQQFxNs5b479NHXopkbWX9U3PAwWAVSY%2FpZf1udQ7rfUpQ1CzurDPpwo16Ff2cMWjuFHX9qCV0Y0Ok4Jvh63IABUNnktl%2B6sgP%2BARIxSrT%2FMhLlAAAAAElFTkSuQmCC)](http://spiceprogram.org/oss-sponsorship)\n\n## Installation\n\nNPM:\n\n```\nnpm install --save-dev mocha-cakes-2\n```\n\n## Usage\n\n### Enable the mocha-cakes-2 integration\n\nTo enable the Mocha integration you need to specify `mocha-cakes-2` in the `ui` option.\n\n#### CLI\n\nEither use the command line argument:\n\n``` javascript\nmocha --ui mocha-cakes-2 path/to/my/tests\n```\n\nOr set it in your [`mocha.opts`](https://mochajs.org/#mochaopts) file:\n\n``` javascript\n--ui mocha-cakes-2\n```\n\n#### API\n\nEither pass it in the options as you construct Mocha:\n\n``` javascript\nvar mocha = new Mocha({\n  ui: 'mocha-cakes-2'\n});\n```\n\nOr set it after you've constructed Mocha:\n\n``` javascript\nvar mocha = new Mocha();\nmocha.ui('mocha-cakes-2')\n```\n\n### Test structure\n\n```javascript\nrequire('chai').should();\n\nFeature('Some feature', () =\u003e {\n\n  Scenario('Some Scenario', () =\u003e {\n\n    let number = 2;\n\n    Given('a number', () =\u003e {\n      number.should.exist;\n    });\n    And('that number is 2', () =\u003e {\n      number.should.equal(2);\n    });\n\n    When('adding 40', () =\u003e {\n      number += 40;\n    });\n\n    Then('the number should be 42', () =\u003e {\n      number.should.equal(42);\n    });\n  });\n});\n```\n\nThe result will look something like this:\n\n\u003cimg src=\"doc/example-feature-v2.png\" width=\"500\" /\u003e\n\nThe common Mocha functions (`describe`, `it`, `before`, `after`, etc) are also available and can be used together with Mocha Cakes.\n\n### Upgrading from version 1.x\n\nReplace the `require('mocha-cakes-2')` statement(s) with the `--ui mocha-cakes-2` option as described above.\n\n### TypeScript\n\nThe TypeScript definitions are bundled together with mocha-cakes-2.\nTo use mocha directly with TypeScript you need types for mocha and [ts-node](https://github.com/TypeStrong/ts-node).\n\n```\nnpm install --save-dev typescript ts-node @types/mocha\n```\n\nYou should have a `tsconfig.json` in the root of your project like so\n\n```json\n{\n  \"compilerOptions\": {\n    \"module\": \"commonjs\",\n    \"moduleResolution\": \"node\"\n  }\n}\n```\n\nNow you can run it like so:\n\n```\nmocha -r ts-node/register --ui mocha-cakes-2  ...\n```\n\nYour tests should look like this:\n\n```\nimport 'mocha-cakes-2';\n\nFeature('Some feature', () =\u003e {\n\n  Scenario('Some Scenario', () =\u003e {\n\n    let number = 2;\n\n    Given('a number', () =\u003e {\n\n    });\n    And('that number is 2', () =\u003e {\n\n    });\n\n    When('adding 40', () =\u003e {\n\n    });\n\n    Then('the number should be 42', () =\u003e {\n\n    });\n  });\n});\n```\n\n## API\n\nThe Mocha Cakes integration adds the following functions to the global scope:\n\n* `Feature | feature`\n  * `Scenario | scenario`\n      - `Given | given`\n      - `When | when`\n      - `Then | then`\n      - `And | and`\n      - `But | but`\n\n### `.skip`\n\nSkips a test clause. Works on all test functions.\n\n```javascript\nFeature('Some feature', () =\u003e {\n\n  Scenario.skip('Skipped scenario', () =\u003e {\n    // ...\n  });\n\n  Scenario('Ordinary', () =\u003e {\n    // ...\n  });\n});\n```\n\n\u003cimg src=\"doc/skipped-v2.png\" width=\"400\" /\u003e\n\n### `.only`\n\nOnly run the specified test clause. Works on all test functions.\n\n```javascript\nFeature('Some feature', () =\u003e {\n\n  Scenario('First scenario', () =\u003e {\n    // ...\n  });\n\n  Scenario('Second scenario', () =\u003e {\n    // ...\n  });\n\n  Scenario.only('Only I will run!', () =\u003e {\n    // ...\n  });\n\n  // ...\n});\n```\n\n\u003cimg src=\"doc/only-v2.png\" width=\"400\" /\u003e\n\n### `beforeEachScenario` and `afterEachScenario`\n\nExecutes the provided function only once for each of the scenarios under the current scope.\n\n```javascript\nFeature('Some feature', () =\u003e {\n\n  beforeEachScenario( () =\u003e {\n    someSetup();\n  });\n\n  afterEachScenario( () =\u003e {\n    doCleanup();\n  });\n\n  Scenario('First scenario', () =\u003e {\n    // ...\n  });\n\n  Scenario('Second scenario', () =\u003e {\n    // ...\n  });\n\n  // ...\n});\n```\n\n### `beforeEachFeature` and `afterEachFeature`\n\nExecutes the provided function only once for each of the features under the current scope.\n\n```javascript\nbeforeEachFeature( () =\u003e {\n  someSetup();\n});\n\nafterEachFeature( () =\u003e {\n  doCleanup();\n});\n\nFeature('Some feature', () =\u003e {\n  // ...\n});\n\nFeature('Another feature', () =\u003e {\n  // ...\n});\n\n// ...\n```\n\n## Development\n\n### Testing the CLI and API interfaces\n\nIf you use Mocha directly to run the tests you can set the `MOCHA_INTERFACE` environment variable to either `cli` or `api` to choose which Mocha interface to run the tests with: `MOCHA_INTERFACE=api mocha test/feature/tests.js`.\n\n`MOCHA_INTERFACE` will default to `cli` if no value is set.\n\nWhen you run `npm run test:cli` or `npm run test:api` (or `npm test` to run them both), `MOCHA_INTERFACE` is set automatically to the appropriate value.\n\n## Acknowledgements\n\nMocha Cakes 2 is heavily influenced by **quangv**'s [mocha-cakes](https://github.com/quangv/mocha-cakes/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiensu%2Fmocha-cakes-2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiensu%2Fmocha-cakes-2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiensu%2Fmocha-cakes-2/lists"}