{"id":21446194,"url":"https://github.com/spazmodius/gwt","last_synced_at":"2026-05-15T01:03:08.063Z","repository":{"id":143019005,"uuid":"171377944","full_name":"spazmodius/gwt","owner":"spazmodius","description":"Super simple Given-When-Then tests in Node.js","archived":false,"fork":false,"pushed_at":"2020-01-30T17:42:24.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-23T11:23:48.886Z","etag":null,"topics":["module","node","testing"],"latest_commit_sha":null,"homepage":"","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/spazmodius.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-19T00:39:27.000Z","updated_at":"2020-01-30T17:42:26.000Z","dependencies_parsed_at":"2023-04-22T17:30:56.841Z","dependency_job_id":null,"html_url":"https://github.com/spazmodius/gwt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spazmodius%2Fgwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spazmodius%2Fgwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spazmodius%2Fgwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spazmodius%2Fgwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spazmodius","download_url":"https://codeload.github.com/spazmodius/gwt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243955951,"owners_count":20374410,"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":["module","node","testing"],"created_at":"2024-11-23T02:42:20.243Z","updated_at":"2025-10-06T22:09:29.897Z","avatar_url":"https://github.com/spazmodius.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Spaz's Given-When-Then\r\n\r\n***Super simple Given-When-Then testing in Node.js***\r\n\r\n## Install and Usage\r\n\r\n`npm install spazmodius/gwt -D`\r\n\r\nExample:\r\n```js\r\nconst given = require('@spazmodius/gwt')\r\nconst crypto = require('crypto')\r\nconst { Buffer } = require('buffer')\r\n\r\ngiven(5)\r\n.when(crypto.randomBytes)\r\n.then(({ returned }) =\u003e returned instanceof Buffer)\r\n.then(({ returned }) =\u003e returned.length === 4)\r\n```\r\n\r\nRunnng the above script, which has 1 passing and 1 failing test, results in the output:\r\n```\r\n───────\r\nGiven 5\r\n When randomBytes\r\n Then returned.length===4\r\nFailed! returned false\r\n════════════════════════════════\r\nTest Summary: 1 passed, 1 failed\r\n```\r\n\r\n## Async Support\r\n\r\nAll functions that are provided to `given()`, `when()`, and `then()` may be async, or return a Promise.\r\n\r\n## Colored Output\r\n\r\nIf the [colors](https://www.npmjs.com/package/colors) package is available,\r\nthen console output will be colored appropriately.\r\nInstalling this package _does not_ automatically install [colors](https://www.npmjs.com/package/colors).\r\n\r\n## API\r\n\r\n### given( _[description], [...values]_ )\r\n### given( _[description], fn, [...args]_ )\r\n\r\n| Argument | Type | Optional | Description\r\n|---|---|:---:|---\r\n`description` | string | \u0026check; | Description of this **Given** clause. If not specified, a description will be generated.\r\n`values` | any | \u0026check; | Zero or more context values (or Promises).\r\n`fn` | function | | A function that returns a single context value or Promise.\r\n`args` | any | \u0026check; | Arguments to be passed to `fn`.\r\n\r\nStart a new test-case.\r\nMay be followed by more `.given()`, or `.when()`.\r\n\r\nYou may provide directly any number of `values` or Promises,\r\nwhich will become context values.\r\n\u003e **Note**: because of the supported signatures, if the first of `values` is a string, then the `description` argument must be provided.\r\nYou may pass `undefined` or `''` to get the generated default.\r\n\r\nAlternatively, provide a function, or async function, along with arguments;\r\nthe return value of `fn(...args)` will become one context value.\r\n\r\nAll context values will be passed to the **when** action, as arguments in the same order that they appear in all the `given()`s.\r\n\r\n### .when( _[description], action, [...more]_ )\r\n\r\n| Argument | Type | Optional | Description\r\n|---|---|:---:|---\r\n`description` | string | \u0026check; | Description of this **When** clause. If not specified, a description will be generated.\r\n`action` | function | | Function that executes the action to test.  May be async.\r\n`more` | any | \u0026check; | More arguments to be passed to `action`.\r\n\r\nSpecify the action to test.\r\nMust be followed by `.then()`.\r\n\r\nThe `action()` will be called with each of the context values,\r\ngenerated by the **given**s,\r\nand any `more` values.\r\nIt can return a value or Promise, or throw an exception, and/or mutate context objects.\r\n\r\n### .then( _[description], expectation, [...more]_ )\r\n\r\n| Argument | Type | Optional | Description\r\n|---|---|:---:|---\r\n`description` | string | \u0026check; | Description of this **Then** clause. If not specified, a description will be generated.\r\n`expectation` | function | | Function that tests the results of the **when** action. May be async. It has signature `(result, context, more...)`.\r\n`more` | any | \u0026check; | Additional arguments to pass to `expectation()`.\r\n\r\nTest an expectation about the results of the **when** action.\r\nMay be followed by more calls to `.then()`.\r\n\r\n`expectation()` will be called with these arguments:\r\n- `result` \\\r\nAn object that captures the result of executing the **when** action,\r\nwith properties:\r\n    * `result.returned` \\\r\n\tThe action's returned or resolved value. If the action threw an error, reading this property will throw that error.\r\n    * `result.threw` \\\r\n\tThe error thrown by the action. if the action did not throw an error, this value is `undefined`.\r\n- `context` \\\r\nAn array of the arguments that were passed to the **when** action.\r\nThese are the context values generated by the **given**s,\r\nand any `more` values provided to `.when()`.\r\n- `more...` \\\r\nAny `more` arguments provided to `.then()` will be passed through to `expectation()`.\r\n\r\nIf `expectation()` returns `true`, or a Promise that resolves to `true`, then the test **passes**.\r\nAny other return or resolution value, or throwing an error, **fails** the test.\r\nIn the case of failure, the return value or thrown error will be reported.\r\n\r\nHowever, if `expectation()` returns or resolves to `undefined`, the test is **inconclusive**.\r\nThis might occur if the `expectation()` makes assertions, but does not end with `return true`.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspazmodius%2Fgwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspazmodius%2Fgwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspazmodius%2Fgwt/lists"}