{"id":23435549,"url":"https://github.com/customcommander/cucumber-js-cukebook","last_synced_at":"2025-07-22T10:07:27.612Z","repository":{"id":46827557,"uuid":"267115057","full_name":"customcommander/cucumber-js-cukebook","owner":"customcommander","description":"Recipes for Cucumber.js","archived":false,"fork":false,"pushed_at":"2024-02-27T04:20:21.000Z","size":34,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-14T04:39:11.148Z","etag":null,"topics":["cookbook","cucumber-js","testing-practices"],"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/customcommander.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-26T18:01:04.000Z","updated_at":"2021-09-23T09:52:25.000Z","dependencies_parsed_at":"2025-02-15T10:26:40.445Z","dependency_job_id":"cd0ea9ec-27d1-4787-b415-5e1df65f088c","html_url":"https://github.com/customcommander/cucumber-js-cukebook","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/customcommander/cucumber-js-cukebook","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/customcommander%2Fcucumber-js-cukebook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/customcommander%2Fcucumber-js-cukebook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/customcommander%2Fcucumber-js-cukebook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/customcommander%2Fcucumber-js-cukebook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/customcommander","download_url":"https://codeload.github.com/customcommander/cucumber-js-cukebook/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/customcommander%2Fcucumber-js-cukebook/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266473086,"owners_count":23934477,"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","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["cookbook","cucumber-js","testing-practices"],"created_at":"2024-12-23T12:51:51.214Z","updated_at":"2025-07-22T10:07:27.521Z","avatar_url":"https://github.com/customcommander.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cukebook\n\nThis cookbook shows how things _can_ be done so we can focus on automation rather than implementation.\n\n## Avoid arrow functions\n\nDon't:\n\n```javascript\ndefineStep('I sign in', () =\u003e {\n  signIn(this.config.username, this.config.password); // TypeError\n});\n```\n\nDo:\n\n```javascript\ndefineStep('I sign in', function () {\n  signIn(this.config.username, this.config.password);\n});\n```\n\nWhy?\n\nCucumber sets the context of a step to the [World][doc-world]. If you use an arrow function that context will be the module implementing the step. Most likely not what you want.\n\n\n\n## Prefer Cucumber expressions over regular expressions\n\nIn most cases you don't need regular expressions and you may find [Cucumber expressions][cucumber-expressions-doc] easier to the eyes.\n\n### Exact match\n\n```javascript\ndefineStep('I will match just this text', function () {\n  //...\n});\n```\n\n```gherkin\nWhen I will match just this text          # match\nThen I will match just this text and more # no match!\n```\n\n### Matching numbers\n\n```javascript\ndefineStep('I order {int} burritos at £{float} each', function (amount, price) {\n  console.log(`${amount} × ${price} = ${amount * price}`);\n});\n\n```\n\n```gherkin\nWhen I order 10 burritos at £4.75 each # amount: 10, price: 4.75\n```\n\n### Matching strings and words\n\n```javascript\n// Match anything between double quotes or single quotes\n// The quotes **are not** part of the match\ndefineStep('the text is {string}', function (str) {\n  console.log(str);\n});\n\n// Match a single word without whitespace\ndefineStep('the name is {word}', function (wrd) {\n  console.log(wrd);\n});\n```\n\n```gherkin\nWhen the text is \"John Doe\" # str: 'John Doe'\nThen the name is generic    # wrd: 'generic'\nWhen the text is \"\"         # str: '' (an empty string)\nThen the name is empty      # wrd: 'empty'\n```\n\n### Pluralisation\n\n```javascript\n// the text in parenthesis is optional\ndefineStep('I see {int} fox(es)', function (num) {\n  console.log(num);\n});\n```\n\n```gherkin\nWhen I see 1 fox    # num: 1\nWhen I see 10 foxes # num: 10\n```\n\n### Alternative(s)\n\n```javascript\n// match any single word separated by a slash\n// ⚠️the match is **not** captured!\ndefineStep('I have a dog/cat/fish', function () {\n  this.owns_pet = true;\n});\n```\n\n```gherkin\nGiven I have a dog  # match\nGiven I have a cat  # match\nGiven I have a fish # match\n```\n\n## Grow your vocabulary with custom types\n\n\n\n```javascript\ndefineStep('I have {quantity} book(s)', function (amount) {\n  console.log(amount);\n});\n\nfunction between(min, max) {\n  return Math.floor(Math.random() * (max - min + 1) + min);\n}\n\ndefineParameterType({\n  name: 'quantity',\n  regexp: /\\d+|no|some/,\n  transformer: qty =\u003e {\n    if (qty === 'no') return 0;\n    if (qty === 'some') return between(1, 10);\n    return qty;\n  }\n});\n```\n\n```gherkin\nGiven I have no book     # amount: 0\nGiven I have 2 books     # amount: 2\nGiven I have some books  # amount: (random number between 1 and 10)\n```\n\n\n\n\n\n\n\n\n\n\n\n[package]: https://github.com/cucumber/cucumber-js\n[doc-world]: https://github.com/cucumber/cucumber-js/blob/master/docs/support_files/world.md\n[cucumber-expressions-doc]: https://cucumber.io/docs/cucumber/cucumber-expressions/","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcustomcommander%2Fcucumber-js-cukebook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcustomcommander%2Fcucumber-js-cukebook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcustomcommander%2Fcucumber-js-cukebook/lists"}