{"id":18456228,"url":"https://github.com/khezen/iotest","last_synced_at":"2026-05-10T06:40:50.575Z","repository":{"id":57276379,"uuid":"83325640","full_name":"khezen/iotest","owner":"khezen","description":"Javascript library to help with unit tests","archived":false,"fork":false,"pushed_at":"2017-03-14T18:29:02.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-16T15:06:52.072Z","etag":null,"topics":["chai","library","nodejs","test"],"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/khezen.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":"2017-02-27T15:30:02.000Z","updated_at":"2018-08-27T06:12:16.000Z","dependencies_parsed_at":"2022-08-25T04:02:31.973Z","dependency_job_id":null,"html_url":"https://github.com/khezen/iotest","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/khezen%2Fiotest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khezen%2Fiotest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khezen%2Fiotest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khezen%2Fiotest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/khezen","download_url":"https://codeload.github.com/khezen/iotest/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249676460,"owners_count":21309423,"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":["chai","library","nodejs","test"],"created_at":"2024-11-06T08:10:56.178Z","updated_at":"2026-05-10T06:40:50.542Z","avatar_url":"https://github.com/khezen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NPM Version](http://img.shields.io/npm/v/iotest.svg?style=flat)](https://www.npmjs.org/package/iotest)\n\n# iotest\n\nJavascript library which makes input/output testing a no-brainer.\n\n# install\n`npm install --save-dev iotest`\n\n# example with mocha\n```javascript\nfunction f(x){\n  return x + 1;\n}\n```\n\nTest cases are processed sequentially when testing multiple cases:\n\n```javascript\nconst iotest = require('iotest');\n\ndescribe('f', () =\u003e {\n  it('should pass i/o tests', (done) =\u003e {\n\n    const cases = [\n      {inputs: 41, return: 42},\n      {inputs: 0, return: 1}\n    ];\n\n    iotest(cases, f).\n    then(outputs =\u003e {\n      console.log(outputs):\n      // =\u003e [42, 1]\n      done();\n    }).\n    reject(done);\n\n  });\n});\n```\n\nTesting one case:\n```javascript\nconst iotest = require('iotest');\n\ndescribe('f', () =\u003e {\n  it('should pass i/o tests', (done) =\u003e {\n\n    const case = { inputs: 41, return: 42 };\n\n    iotest(case, f).\n    then(outputs =\u003e {\n      console.log(outputs):\n      // =\u003e [42]\n      done();\n    }).\n    reject(done);\n\n  });\n});\n```\n\n# case\nJSON object describing a test case.\n\n## case.inputs\nGiven arguments of a function.\n### single input\n```javascript\nfunction f(x){\n  return x + 1;\n}\n```\n\n```javascript\nconst iotest = require('iotest');\n\nconst cases = [\n  { inputs: 41, return: 42 },    // succeed\n  { inputs: [41], return: 42 },  // succeed\n];      \n\niotest(cases, f).\nthen(outputs =\u003e { /* tests succeed */ }).\ncatch(err =\u003e { /* tests failed */ });\n```\n\n### multiple inputs\n```javascript\nfunction f(x, y){\n  return x + y;\n}\n```\n\n```javascript\nconst iotest = require('iotest');\n\nconst case = { inputs: [10, 32], return: 42} // succeed    \n\niotest(case, f).\nthen(outputs =\u003e { /* tests succeed */ }).\ncatch(err =\u003e { /* tests failed */ });\n```\n\n## case.return / case.error\nExpected returned output of a function / Expected error thrown by a function.\n\n```javascript\nfunction f(x, y){\n  if(y === 0){\n    throw new Error(\"division by 0\");\n  }\n  return x / y;  \n}\n```\n\n```javascript\nconst iotest = require('iotest');\n\nconst cases = [\n  { inputs: [42, 0], error: {} },   // succeed\n  { inputs: [42, 2], return: 21 },  // succeed\n];   \n\niotest(cases, f).\nthen(outputs =\u003e { /* tests succeed */ }).\ncatch(err =\u003e { /* tests failed */ });\n```\n\n## case.resolve / case.reject\nExpected resolved value / Expected rejected error, of the promise returned by a function.\n\n```javascript\nfunction f(x, y){\n  return new Promise( (resolve, reject) =\u003e {\n    if(y === 0){\n      reject(new Error(\"division by 0\"));\n    }else{\n      resolve(x / y);  \n    }\n  });\n}\n```\n\n```javascript\nconst iotest = require('iotest');\n\nconst cases = [\n  { inputs: [42, 0], reject: {} },   // succeed\n  { inputs: [42, 2], resolve: 21 },  // succeed\n];   \n\niotest(cases, f).\nthen(outputs =\u003e { /* tests succeed */ }).\ncatch(err =\u003e { /* tests failed */ });\n```\n\n## depth traversal\nif `case.return`, `case.error`, `case.resolve` or `case.reject` is set with an *Object*, then it is deeply traversed to make sure each property exists with the right value in the `output`.\n\n```javascript\nfunction f(x){\n  return {\n    x: x,\n    y: x + 1\n  };\n}\n```\n\n```javascript\nconst iotest = require('iotest');\n\nconst cases = [\n  { inputs: 41, return: {x: 41} },              // succeed\n  { inputs: 0, return: {y: 1} },                // succeed\n  { inputs: 1000, return: {x: 1000, y: 1001} }, // succeed\n  { inputs: 7, return: {} }                     // succeed\n];\n\niotest(cases, f).\nthen(outputs =\u003e { /* tests succeed */ }).\ncatch(err =\u003e { /* tests failed */ });\n```\n\nif `case.return`, `case.error`, `case.resolve` or `case.reject` is set with an *Array*, then each item is deeply traversed.\n\n```javascript\nfunction f(x){\n  return [\n    { x: x, y: x + 1 },\n    { x: x, y: y - 1 }\n  ];\n}\n\n```\n\n```javascript\nconst iotest = require('iotest');\n\nconst case = {\n  inputs: 41,\n  return: [\n    {x: 41, y: 42},\n    {y: 40}\n  ]\n}; // succeed\n\n\niotest(case, f).\nthen(outputs =\u003e { /* tests succeed */ }).\ncatch(err =\u003e { /* tests failed */ });\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhezen%2Fiotest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkhezen%2Fiotest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhezen%2Fiotest/lists"}