{"id":14971497,"url":"https://github.com/kevindoole/fredastaire","last_synced_at":"2026-02-27T22:14:17.203Z","repository":{"id":57241484,"uuid":"95276443","full_name":"kevindoole/fredastaire","owner":"kevindoole","description":"Mocha-given adds a `given` method, which makes it really easy to succinctly and readably set up a test case.","archived":false,"fork":false,"pushed_at":"2017-07-03T04:04:27.000Z","size":14,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-16T00:31:07.814Z","etag":null,"topics":["bdd","cucumber","given","mocha","mocha-tests","test-setup"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kevindoole.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-24T04:50:12.000Z","updated_at":"2017-07-03T04:06:08.000Z","dependencies_parsed_at":"2022-09-08T00:40:54.463Z","dependency_job_id":null,"html_url":"https://github.com/kevindoole/fredastaire","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevindoole%2Ffredastaire","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevindoole%2Ffredastaire/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevindoole%2Ffredastaire/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevindoole%2Ffredastaire/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevindoole","download_url":"https://codeload.github.com/kevindoole/fredastaire/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239854252,"owners_count":19708034,"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","given","mocha","mocha-tests","test-setup"],"created_at":"2024-09-24T13:45:17.468Z","updated_at":"2026-02-27T22:14:12.183Z","avatar_url":"https://github.com/kevindoole.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fredastaire\nFredastaire adds step methods to mocha tests that have two impacts:\n- Your test cases' setup code is significantly more readable\n- You only have to write the same setup steps once\n\n## Table of contents\n- [Setup](#setup)\n- [Usage](#usage)\n  - [Tests](#1-tests)\n  - [Step definitions](#2-step-definitions)\n- [Full API](#full-api)\n\n---\n\n## Setup\n0. `npm install fredastaire --save-dev` or `yarn add fredastaire -D`\n1. Define your steps wherever you like. (example below)\n2. Write some tests that use `given`. (example below)\n3. Run your tests with the fredastaire ui, requiring your steps file:\n  `mocha ./tests/some-tests.js --ui fredastaire --require \u003cyour steps file\u003e`\n\n## Usage\n\n### 1. Tests\nJust call `given('with some string')`. The string will be used to identify which step definition to call (more on that later).\n\nThere's also `when` and `and`, which are aliases of `given`.\n\nTODO: Add given, when, and to the test output.\n\n```js\n// /your/project/tests/astronauts-test.js\n\nconst state = {\n\tspaceThings: [],\n\tastronauts: [],\n};\n\nlet res;\n\ndescribe('Interesting space apparatus example', function() {\n\tgiven('there are two spacethings', {container: state.spaceThings});\n\n\tand('there is one astronaut', {container: state.astronauts});\n\n\twhen('i request a space thing that has an astronaut', {\n\t\tid: state.spaceThings[0].id,\n\t\tcontainer: res,\n\t});\n\n\tit('should give me one space thing', function() {\n\t  expect(res.body.spacething).to.not.be.null;\n\t  expect(res.body.spacething.id).to.equal(state.spacethings[0].id);\n\t});\n\n\tit('should have an astronaut with the space thing', function() {\n\t\texpect(res.body.spacething.astronaut).to.not.be.null;\n\t\texpect(res.body.spacething.astronaut.id).to.equal(state.astronauts[0].id);\n\t});\n});\n```\n\n### 2. Step definitions\nStep definitions are the places where you put your setup code for individual tests.\n\n```js\n// /your/project/wherever/you/like/your-definitions.js\n\nconst addSteps = require('fredastaire/steps');\nconst request = require('whatever/you/like/for/requesting/stuff');\n\naddSteps({\n  'there are two space things': function({container, spaceThing1={}, spaceThing2={}}) {\n    container = [SpaceThings.create(spaceThing1), SpaceThings.create(spaceThing2)];\n  },\n\n  'there is one astronaut': function({container, astronaut={}}) {\n    container = SpaceAstronaut.create(astronaut);\n  },\n\n  'i request a space thing that has an astronaut': function({id, container}) {\n    return request.get('/space-things/' + id)\n    .then(response =\u003e container = response);\n  }\n});\n```\n\n## Full API\n\n### Methods\n\n---\n\n#### `given`, `and`, `when`\n\n```js\ngiven('there is something', {named: 'whatever'});\n```\n\nCalls a defined step inside a `before`. `given`, `and` and `when` are all the\nsame function, so use them in whatever order you like. Return a promise to\nhandle async behavior.\n\n##### Arguments\n\n###### {string} `name` -- The name used to identify the step.\nSo if you define a step named \"this is a step\", then you would run the step\nusing `given('this is a step')`.\n\n###### {object} `data` -- Whatever you need to pass to the step.\nPass whatever your step needs to can create something specific.\n\n---\n\n#### `addSteps`\n\n```js\naddSteps({\n  'there is something': function(data) {\n\t\tglobal.thing = {...data};\n  }\n});\n```\n\nRegisters steps which are triggered with `given`.\n\n##### Arguments\n###### {object} `steps` -- The name and function to be triggered by `given`.\nThe objects you pass to `addSteps` are all merged together, so when you call `given(name)`, it calls `steps[name]()`. *So if you pass the same key twice to `addSteps`, the first step will be replaced by the second.\n\n---\n\n#### `getSteps()`\n\nGets all the steps you've defined\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevindoole%2Ffredastaire","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevindoole%2Ffredastaire","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevindoole%2Ffredastaire/lists"}