{"id":17349193,"url":"https://github.com/co2-git/redtea","last_synced_at":"2025-03-27T11:44:18.769Z","repository":{"id":68259631,"uuid":"47642888","full_name":"co2-git/redtea","owner":"co2-git","description":"A test framework for JavaScript","archived":false,"fork":false,"pushed_at":"2016-08-05T02:50:42.000Z","size":304,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T16:23:11.820Z","etag":null,"topics":[],"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/co2-git.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":"2015-12-08T19:00:41.000Z","updated_at":"2016-10-08T11:23:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"a8b5c3d7-b2e6-45dd-8a97-4c250540d23b","html_url":"https://github.com/co2-git/redtea","commit_stats":null,"previous_names":[],"tags_count":48,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co2-git%2Fredtea","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co2-git%2Fredtea/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co2-git%2Fredtea/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/co2-git%2Fredtea/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/co2-git","download_url":"https://codeload.github.com/co2-git/redtea/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245841690,"owners_count":20681184,"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":[],"created_at":"2024-10-15T16:55:01.100Z","updated_at":"2025-03-27T11:44:18.739Z","avatar_url":"https://github.com/co2-git.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"redtea\n===\n\nTest framework for JavaScript.\n\n# Usage\n\n```javascript\n// test.js\nimport describe from 'redtea';\n\nexport default describe.batch(\n  'My tests',\n    describe('Number', 1, {type: Number}),\n);\n```\n\n```bash\nsudo npm install --global redtea\nnpm install --save-dev redtea\nredtea test.js\n```\n\n```\nMy tests\n  Number (number 1)\n    √ is a Number\n\n1 test(s), 1 passed, 0 failed\n```\n\n# `describe`\n\n`describe()` is the core function of `redtea`. It will assert a given value against an object of properties.\n\n## Notation\n\n```javascript\ntype DESCRIBE = (label: string, value: any, assertions: ASSERTIONS) =\u003e Function;\n```\n\n## Example\n\n```javascript\ndescribe('Is a number and is equal to 10', 10, {type: Number, value: 10});\n```\n\n# `batch`\n\nUse `batch` if you want to group tests together. You can use nested groups of tests this way too.\n\n## Notation\n\n```javascript\ntype BATCH = (label: string, ...tests: Array\u003cFunction\u003e) =\u003e Function;\n```\n\n## Example\n\n```javascript\ndescribe.batch('Groups',\n  describe.batch('Group 1'),\n  describe.batch('Group 2',\n    describe.batch('Group 3'),\n  ),\n);\n```\n\n# `promise`\n\nYou can evaluate the return of a promise using `promise`.\n\n## Notation\n\n```javascript\ntype PROMISE = (label: string, promise: () =\u003e Promise, assertions: ASSERTIONS);\n```\n\n## Example\n\n```javascript\ndescribe.promise(\n  'it should fulfill \"hello\"',\n  () =\u003e new Promise(resolve =\u003e resolve('hello')),\n  {value: 'hello'}\n);\n\n// Catching errors\ndescribe.promise(\n  'it should reject promise',\n  () =\u003e new Promise((resolve, reject) =\u003e reject(new Error('Ouch'))),\n  {\n    type: Error,\n    has: {message: 'Ouch'},\n  }\n);\n```\n\n# `emitter`\n\nYou can also assert events emitted by an emitter.\n\n## Notation\n\n```javascript\ntype EMITTER = (label: string, emitter: () =\u003e EventEmitter, assertions: ASSERTIONS);\n```\n\n## Example\n\n```javascript\nimport {EventEmitter} from 'events';\n\nclass Emitter extends EventEmitter {\n  constructor(name) {\n    super();\n    this.name = name;\n    process.nextTick(::this.greetings);\n  }\n  greetings() {\n    this.emit('hello', this.name);\n  }\n}\n\ndescribe.emitter(\n  'it should greet \"hello John\"',\n  () =\u003e new Emitter('John'),\n  {\n    emits: {\n      hello: {\n        wait: 250,\n        value: 'John',\n      }\n    }\n  }\n);\n\n// Make sure some events are not emitted\ndescribe.emitter(\n  'it should not throw error',\n  () =\u003e new Emitter('John'),\n  {\n    not: {\n      emits: {\n        error: 5000,\n      }\n    },\n  }\n);\n```\n\n# Assertions\n\n## Notations\n\n```javascript\ntype ASSERTIONS = {\n  type?: TYPE,\n  types?: TYPE[],\n  mixed?: TYPE[],\n  mixedArray?: TYPE[],\n  value?: any,\n  has?: any,\n  shape?: Object,\n  some?: (item: any, index: number, items: Array\u003cany\u003e) =\u003e boolean,\n  every?: (item: any, index: number, items: Array\u003cany\u003e) =\u003e boolean,\n  above: number | Date,\n  below: number | Date,\n  not?: ASSERTIONS,\n  emits: EMITTERS,\n};\n\ntype TYPE = Function | null | TYPE_EXTRA | Array\u003cFunction | null | TYPE_EXTRA\u003e;\n\ntype TYPE_EXTRA = {\n  mixed?: [TYPE],\n};\n\ntype EMITTERS = {\n  [event: string]: ASSERTIONS \u0026 {wait?: Number},\n};\n```\n\n## `value: any`\n\nThe value to match that. We use lodash's [isEqual](https://lodash.com/docs#isEqual) for comparisons.\n\n```javascript\ndefine('Value', 10, {value: 10});\n```\n\n## `type: TYPE`\n\nType comparison.\n\n```javascript\ndefine('Is null', null, {type: null});\ndefine('Is a regular expression', /a/, {type: RegExp});\n\nclass Foo {}\ndefine('Is a foo', new Foo(), {type: Foo});\n\n// Arrays\ndefine('Array type', [1, 2, 3], {type: [Number]});\n```\n\n## `mixed: Array\u003cTYPE\u003e`\n\n```javascript\ndefine('Is either number or string', 1, {mixed: [Number, String]});\n```\n\n## `mixedArray: Array\u003cTYPE\u003e`\n\n```javascript\ndefine('Items are either boolean or an array of numbers', [true, [1]], {mixedArray: [Boolean, [Number]]});\n```\n\n## `has: any`\n\n## String\n\nWill perform a regular expression\n\n```javascript\ndefine('Has abc', 'abcdefgh', {has: /abc/});\n```\n\n## Array\n\nHas at least one item matching.\n\n```javascript\ndefine('Has 1', [1, 2, 3], {has: 1});\n```\n\n## Object\n\nCheck if properties exist.\n\n```javascript\ndefine('Has foo: 1', {foo: 1, bar: 2}, {has: {foo: 1}});\n// property exists\ndefine('Has foo', {foo: 1, bar: 2}, {has: 'foo'});\n// properties exist\ndefine('Has foo and bar', {foo: 1, bar: 2}, {has: ['foo', 'bar']});\n```\n\n## `some: (item: any, index: number, items: Array\u003cany\u003e) =\u003e boolean`\n\nCheck if some items of the array match.\n\n```javascript\ndefine(\n  'At least 1 item greater than 5',\n  [1, 5, 10],\n  {some: (number =\u003e number \u003e 5)}\n);\n```\n\n## `every: (item: any, index: number, items: Array\u003cany\u003e) =\u003e boolean`\n\nCheck if every items of the array match.\n\n```javascript\ndefine(\n  'All items greater than 5',\n  [10, 15, 20],\n  {every: (number =\u003e number \u003e 5)}\n);\n```\n\n## `above: number | Date`\n\n```javascript\ndefine(\n  'Number is above 2',\n  3,\n  {above: 2}\n);\n\ndefine(\n  'Date is in the future',\n  new Date([2020]),\n  {above: new Date()}\n);\n```\n\n## `below: number | Date`\n\n```javascript\ndefine(\n  'Number is below 2',\n  1,\n  {below: 2}\n);\n\ndefine(\n  'Date is in the past',\n  new Date([1980]),\n  {below: new Date()}\n);\n```\n\n## `between: Array\u003cnumber\u003e | Array\u003cDate\u003e`\n\n```javascript\ndefine(\n  'Number is between 1 and 3',\n  2,\n  {between: [1, 3]}\n);\n\ndefine(\n  'Date is between last year and next year',\n  new Date(),\n  {between: [new Date([2015]), new Date([2016])]}\n);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fco2-git%2Fredtea","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fco2-git%2Fredtea","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fco2-git%2Fredtea/lists"}