{"_id":"bdd-stdin","_rev":"228000","name":"bdd-stdin","description":"Utility for easily mocking user responses for BDD unit tests that ask user a question.","dist-tags":{"latest":"0.2.0"},"maintainers":[{"name":"bahmutov","email":"gleb.bahmutov@gmail.com"}],"time":{"modified":"2021-06-03T15:44:05.000Z","created":"2015-05-04T03:04:33.727Z","0.2.0":"2015-05-05T02:16:42.964Z","0.1.1":"2015-05-04T04:15:52.120Z","0.1.0":"2015-05-04T03:04:33.727Z"},"users":{},"author":{"name":"Gleb Bahmutov","email":"gleb.bahmutov@gmail.com"},"repository":{"type":"git","url":"https://github.com/bahmutov/bdd-stdin.git"},"versions":{"0.2.0":{"name":"bdd-stdin","version":"0.2.0","description":"Utility for easily mocking user responses for BDD unit tests that ask user a question.","main":"index.js","scripts":{"test":"mocha -R spec test/*-spec.js"},"repository":{"type":"git","url":"https://github.com/bahmutov/bdd-stdin.git"},"keywords":["bdd","tdd","unit","test","test","mocha","jasmine","utility","stdin","response"],"author":{"name":"Gleb Bahmutov","email":"gleb.bahmutov@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/bahmutov/bdd-stdin/issues"},"homepage":"https://github.com/bahmutov/bdd-stdin","devDependencies":{"bluebird":"2.9.25","inquirer":"0.8.3","mocha":"2.2.4","pre-git":"0.2.1"},"dependencies":{"mock-stdin":"0.3.0"},"pre-commit":["npm test -- --grep nogit --invert","npm version"],"gitHead":"487fbef310b59d048b170f28ee8e8670b65daccb","_id":"bdd-stdin@0.2.0","_shasum":"04e66aa480e0e0df861e288a4062fb8557db2441","_from":".","_npmVersion":"2.1.16","_nodeVersion":"0.11.10","_npmUser":{"name":"bahmutov","email":"gleb.bahmutov@gmail.com"},"maintainers":[{"name":"bahmutov","email":"gleb.bahmutov@gmail.com"}],"dist":{"shasum":"04e66aa480e0e0df861e288a4062fb8557db2441","size":3578,"noattachment":false,"key":"/bdd-stdin/-/bdd-stdin-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/bdd-stdin/download/bdd-stdin-0.2.0.tgz"},"directories":{},"publish_time":1430792202964,"_cnpm_publish_time":1430792202964,"_hasShrinkwrap":false},"0.1.1":{"name":"bdd-stdin","version":"0.1.1","description":"Utility for easily mocking user responses for BDD unit tests that ask user a question.","main":"index.js","scripts":{"test":"mocha -R spec test/*-spec.js"},"repository":{"type":"git","url":"https://github.com/bahmutov/bdd-stdin.git"},"keywords":["bdd","tdd","unit","test","test","mocha","jasmine","utility","stdin","response"],"author":{"name":"Gleb Bahmutov","email":"gleb.bahmutov@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/bahmutov/bdd-stdin/issues"},"homepage":"https://github.com/bahmutov/bdd-stdin","devDependencies":{"bluebird":"2.9.25","mocha":"2.2.4","pre-git":"0.2.1"},"dependencies":{"mock-stdin":"0.3.0"},"pre-commit":["npm test","npm version"],"gitHead":"95dbad23285a1c4a718fa9f486f81034a117f1c7","_id":"bdd-stdin@0.1.1","_shasum":"0c96728c7898f22abb77af03c723b24045636330","_from":".","_npmVersion":"2.1.16","_nodeVersion":"0.11.10","_npmUser":{"name":"bahmutov","email":"gleb.bahmutov@gmail.com"},"maintainers":[{"name":"bahmutov","email":"gleb.bahmutov@gmail.com"}],"dist":{"shasum":"0c96728c7898f22abb77af03c723b24045636330","size":2873,"noattachment":false,"key":"/bdd-stdin/-/bdd-stdin-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/bdd-stdin/download/bdd-stdin-0.1.1.tgz"},"directories":{},"publish_time":1430712952120,"_cnpm_publish_time":1430712952120,"_hasShrinkwrap":false},"0.1.0":{"name":"bdd-stdin","version":"0.1.0","description":"Utility for easily mocking user responses for BDD unit tests that ask user a question.","main":"index.js","scripts":{"test":"mocha -R spec test/*-spec.js"},"repository":{"type":"git","url":"https://github.com/bahmutov/bdd-stdin.git"},"keywords":["bdd","tdd","unit","test","test","mocha","jasmine","utility","stdin","response"],"author":{"name":"Gleb Bahmutov","email":"gleb.bahmutov@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/bahmutov/bdd-stdin/issues"},"homepage":"https://github.com/bahmutov/bdd-stdin","devDependencies":{"bluebird":"2.9.25","mocha":"2.2.4","pre-git":"0.2.1"},"dependencies":{"mock-stdin":"0.3.0"},"pre-commit":["npm test","npm version"],"gitHead":"52a1325eb62233266b632e4d4f0bb410d92fdc48","_id":"bdd-stdin@0.1.0","_shasum":"eb5158f11a60f6c53606bef5248644569beaeceb","_from":".","_npmVersion":"2.1.16","_nodeVersion":"0.11.10","_npmUser":{"name":"bahmutov","email":"gleb.bahmutov@gmail.com"},"maintainers":[{"name":"bahmutov","email":"gleb.bahmutov@gmail.com"}],"dist":{"shasum":"eb5158f11a60f6c53606bef5248644569beaeceb","size":2734,"noattachment":false,"key":"/bdd-stdin/-/bdd-stdin-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/bdd-stdin/download/bdd-stdin-0.1.0.tgz"},"directories":{},"publish_time":1430708673727,"_cnpm_publish_time":1430708673727,"_hasShrinkwrap":false}},"readme":"# bdd-stdin\n\n> Utility for easily mocking user responses for BDD unit tests that ask user a question.\n\n[![NPM][bdd-stdin-icon]][bdd-stdin-url]\n\n[![Build status][ci-image]][ci-url]\n[![dependencies][dependencies-image]][dependencies-url]\n[![devdependencies][bdd-stdin-devdependencies-image] ][bdd-stdin-devdependencies-url]\n\nI needed something to help [unit testing CLI apps](http://glebbahmutov.com/blog/unit-testing-cli-programs/).\n\n`npm install bdd-stdin --save-save`\n\n## typing text\n\n```js\nvar ask = require('./ask');\n// ask is promise-returning stdin question\nvar bddStdin = require('bdd-stdin');\ndescribe('ask', function () {\n  it('asks one question', function () {\n    bddStdin('answer');\n    return ask('type \"answer\"')\n      .then(function (response) {\n        console.assert(response === 'answer');\n      });\n  });\n});\n```\n\nYou can provide multiple answers to be delivered in turns\n\n```js\nvar ask = require('./ask');\nvar bddStdin = require('bdd-stdin');\ndescribe('ask', function () {\n  it('asks one question', function () {\n    bddStdin('one', 'two');\n    return ask('type \"one\"')\n      .then(function (response) {\n        console.assert(response === 'one');\n        return ask('type \"two\"');\n      })\n      .then(function (response) {\n        console.assert(response === 'two');\n      });\n  });\n});\n```\n\nYou can even provide answers before each question individually\n\n```js\nit('asks three questions separately', function () {\n  bddStdin('one');\n  return ask('question 1')\n    .then(function (response) {\n      console.assert(response === 'one', 'received response ' + response);\n      bddStdin('two');\n      return ask('question 2');\n    })\n    .then(function (response) {\n      console.assert(response === 'two', 'received response ' + response);\n      bddStdin('three');\n      return ask('question 3');\n    }).then(function (response) {\n      console.assert(response === 'three', 'received response ' + response);\n    });\n});\n```\n\n## selecting choice using up / down keys\n\nIf you use a 3rd party library, like [inquirer](https://github.com/SBoudrias/Inquirer.js) you need to select\nthe right choice using up / down keys. The `bddStdin` object has object property `keys` with `up`, `down`, `left`\nand `right` codes. \n\nFor example the follwing code\n\n```js\nvar inquirer = require('inquirer');\nvar question = {\n  type: 'list',\n  name: 'choice',\n  message: 'pick three',\n  choices: ['one', 'two', 'three']\n};\ninquirer.prompt([question], function (answers) {\n  console.log('user picked', answers.choice);\n});\n```\n\npresents the user with the following prompt:\n\n    ? pick three: (Use arrow keys)\n    ❯ one \n      two \n      three\n\nWe can provide mock answer in our unit tests\n\n```js\nvar bddStdin = require('bdd-stdin');\nit('selects the third choice', function (done) {\n  bddStdin(bddStdin.keys.down, bddStdin.keys.down, '\\n');\n  var question = {\n    type: 'list',\n    name: 'choice',\n    message: 'pick three',\n    choices: ['one', 'two', 'three']\n  };\n  inquirer.prompt([question], function (answers) {\n    console.assert(response === 'three', 'received response ' + response);\n    done();\n  });\n});\n```\n\n### Small print\n\nAuthor: Gleb Bahmutov &copy; 2015\n\n* [@bahmutov](https://twitter.com/bahmutov)\n* [glebbahmutov.com](http://glebbahmutov.com)\n* [blog](http://glebbahmutov.com/blog)\n\nLicense: MIT - do anything with the code, but don't blame me if it does not work.\n\nSpread the word: tweet, star on github, etc.\n\nSupport: if you find any problems with this module, email / tweet /\n[open issue](https://github.com/bahmutov/bdd-stdin/issues) on Github\n\n## MIT License\n\nCopyright (c) 2015 Gleb Bahmutov\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the \"Software\"), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n\n[bdd-stdin-icon]: https://nodei.co/npm/bdd-stdin.png?downloads=true\n[bdd-stdin-url]: https://npmjs.org/package/bdd-stdin\n\n[ci-image]: https://travis-ci.org/bahmutov/bdd-stdin.png?branch=master\n[ci-url]: https://travis-ci.org/bahmutov/bdd-stdin\n[dependencies-image]: https://david-dm.org/bahmutov/bdd-stdin.png\n[dependencies-url]: https://david-dm.org/bahmutov/bdd-stdin\n[bdd-stdin-devdependencies-image]: https://david-dm.org/bahmutov/bdd-stdin/dev-status.png\n[bdd-stdin-devdependencies-url]: https://david-dm.org/bahmutov/bdd-stdin#info=devDependencies\n\n","_attachments":{},"homepage":"https://github.com/bahmutov/bdd-stdin","bugs":{"url":"https://github.com/bahmutov/bdd-stdin/issues"},"license":"MIT"}