{"name":"@cloudcmd/stub","version":"3.7.1","author":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com","url":"https://github.com/coderaiser"},"description":"simplest sinon.stub alternative with diff support","homepage":"http://github.com/coderaiser/cloudcmd/stub","main":"lib/stub.js","repository":{"type":"git","url":"git://github.com/cloudcmd/stub.git"},"scripts":{"test":"madrun test","test:dts":"madrun test:dts","watch:test":"madrun watch:test","lint":"madrun lint","fresh:lint":"madrun fresh:lint","lint:fresh":"madrun lint:fresh","fix:lint":"madrun fix:lint","coverage":"madrun coverage","report":"madrun report","wisdom":"madrun wisdom"},"dependencies":{"chalk":"^4.0.0","strip-ansi":"^6.0.0","jest-diff":"^27.0.6"},"keywords":["sinon","stub","async","promise","calledWith","diff","tape"],"devDependencies":{"c8":"^7.5.0","check-dts":"^0.5.5","coveralls":"^3.0.0","eslint":"^8.0.0-beta.0","eslint-plugin-node":"^11.0.0","eslint-plugin-putout":"^10.3.0","madrun":"^8.0.5","mock-require":"^3.0.2","nodemon":"^2.0.0","putout":"^20.4.0","supertape":"^6.0.2","try-catch":"^3.0.0","try-to-catch":"^3.0.0"},"license":"MIT","engines":{"node":">=10"},"publishConfig":{"access":"public"},"gitHead":"11a7fd1a371fd0a2e49210530ad10f9f6cd2c63b","bugs":{"url":"https://github.com/cloudcmd/stub/issues"},"_id":"@cloudcmd/stub@3.7.1","_nodeVersion":"16.8.0","_npmVersion":"7.21.0","dist":{"integrity":"sha512-N/2/1kOUomQEb0S2ZlLJmL5NBQgKnlepe1Y60urEklrTKP7LNDyqGf24XRdkaJYLi5i6/jgL3vbacNvZTqf5Og==","shasum":"2358c0a420b8e8560f35746ef34faf8f4e98b587","tarball":"http://registry-npm.ywwl.com/@cloudcmd/stub/download/@cloudcmd/stub-3.7.1.tgz","fileCount":7,"unpackedSize":11684,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhzc2XCRA9TVsSAnZWagAARoQP/jv2NRgeXVrR3/z5ytkd\nbBmOlivi/k66fD/lBfsFQtiEfNTzo7YDwxBHoZNQhIfmREYgPNpRGCGW2jEk\ndzx60pAHCdSsdu/yzxVQMqVfM7ZbA4qx19m0zmUz7cuZ2Ogvr2+gjCUTsmti\nYbFnl4nd2lZfLaRYzSyQAAzCBKmR9+X9usr17wdOr7N5iOX8XG3KKCQ06V0B\n0vxMbBZGDlsRZCX/0X03v1ikAca7+CgHTcEUAFqk5UetYM81ecjfYiXtLROL\no8ecLJeilyi1e7VLzumSHteVlO+tWTuBBzhRTEAkVB0EFBIE11MtT1WtIbrh\nR7CIs9WdgCe1wdoQHhAbTyFZBFuMhsUWWlnmpj1yNkveqX6upFjRVPSAgnFD\n2g+9ltMkPkURv0ZSfopYYXZq8eo/gZTVJ5dmQWIdAu2M9GY7D2mqJlst/7LF\nsY7WLWeLceCS+nAhuZtMXPBbTOdzafqk1+qsA7X8HlVM3pov3JlguxbJhdlp\n8dLJfiFbe2rn58yy11uWL4Pyr6kUMpxlEIUY3bF5a6GrG7czAsCa+H+b9yyQ\nbodQDaUWhK9HL9K+UC7YME3jaKjZzqyd2QoA7rFnuzFjihLrVJMhv9Rn7FbZ\nB0Et6VMJ27m0ZQk7GNAb7LRW7T7CWdhgis9HT/3buXHPsnY68T9OVo6uR9Sx\nSfgh\r\n=8uNh\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICWUXP98d/AUccE8q4ytAzG2Xf+WZCWV4mfx6b2RRfkYAiEAxZdm/VLc4xSCrqlGtr/2ge3I/a8KIJwOATBeyWBKGtk="}],"size":4022,"noattachment":false,"key":"/@cloudcmd/stub/-/@cloudcmd/stub-3.7.1.tgz"},"_npmUser":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"directories":{},"maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/stub_3.7.1_1632423232458_0.08250702507660956"},"_hasShrinkwrap":false,"readme":"# Stub [![NPM version][NPMIMGURL]][NPMURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![Coverage Status][CoverageIMGURL]][CoverageURL]\n\n[NPMIMGURL]: https://img.shields.io/npm/v/@cloudcmd/stub.svg?style=flat&longCache=true\n[BuildStatusURL]: https://github.com/coderaiser/putout/actions?query=workflow%3A%22Node+CI%22 \"Build Status\"\n[BuildStatusIMGURL]: https://github.com/coderaiser/putout/workflows/Node%20CI/badge.svg\n[NPMURL]: https://npmjs.org/package/@cloudcmd/stub \"npm\"\n[CoverageURL]: https://coveralls.io/github/cloudcmd/stub?branch=master\n[CoverageIMGURL]: https://coveralls.io/repos/cloudcmd/stub/badge.svg?branch=master&service=github\n\nSimplest [sinon.stub()](https://sinonjs.org/) alternative. With support of showing diff on `calleddWith`.\n\n## Install\n\n```\nnpm i @cloudcmd/stub\n```\n\n## API\n\n### stub([impl])\n\n- `impl` - stub implementation\n\n```js\nconst stub = require('@cloudcmd/stub');\nconst fn = stub();\n// fn contains stubbed function\n\nconst asyncFn = stub(async () => {\n    throw Error('hi');\n});\n\n// asyncFn contains stub async function\n```\n\n### stub().returns([value])\n\n```js\nconst fn = stub().returns('hello');\nfn();\n// returns\n'hello';\n```\n\n### stub().throws([error])\n\n```js\nconst fn = stub().throws(Error('hello'));\nfn();\n// throws\nError('hello');\n```\n\n### stub().rejects([error])\n\n```js\nconst fn = stub().rejects(Error('hello'));\nawait fn();\n// rejects\nError('hello');\n```\n\n### stub().resolves([values])\n\n```js\nconst fn = stub().resolves('hello');\nawait fn();\n// resolves\n'hello';\n```\n\n### stub().calledWith([args])\n\n```js\nconst fn = stub();\n\nfn('hello', 'world');\n\nfn.calledWith('hello', 'world');\n// returns true\n```\n\n### stub().calledWithNew()\n\n```js\nconst fn = stub();\n\nnew fn();\n\nfn.calledWithNew();\n// returns\ntrue;\n```\n\n### stub().calledBefore(fn)\n\n```js\nconst fn1 = stub();\nconst fn2 = stub();\n\nfn1();\nfn2();\n\nfn1.calledBefore(fn2);\n// returns\ntrue;\n```\n\n### stub().calledAfter(fn)\n\n```js\nconst fn1 = stub();\nconst fn2 = stub();\n\nfn1();\nfn2();\n\nfn2.calledAfter(fn1);\n// returns\ntrue;\n```\n\n### stub().called\n\n```js\nconst fn = stub();\n\nfn.called;\n// returns\nfalse;\n\nfn();\n\nfn.called;\n// returns\ntrue;\n```\n\n### stub().callCount\n\n```js\nconst fn = stub();\n\nfn.callCount;\n// returns\n0;\n\nfn();\n\nfn.callCount;\n// returns\n1;\n```\n\n### stub().args\n\n```js\nconst fn = stub();\n\nfn.args;\n// returns\n[];\n\nfn(1);\n\nfn.args;\n// returns\n[[1]];\n```\n\n### stub().callId\n\nEach `stub` has it `callId`, which can be used to determine order of `stub` calls:\n\n```js\nconst fn1 = stub();\nconst fn2 = stub();\n\nfn1();\nfn2();\n\nfn1.callId;\n// returns\n1;\n\nfn2.callId;\n// returns\n2;\n```\n\n### isStub(fn)\n\nCheck if provided function is stub.\n\n```js\nconst {stub, isStub} = require('@cloudcmd/stub');\nconst fn = stub();\n\nisStub(fn);\n// returns\ntrue;\n\nisStub(() => {});\n// returns\nfalse;\n```\n\n## Related\n\n- [sinon-called-with-diff](https://github.com/coderaiser/sinon-called-with-diff) - sinon `calledWith` diff\n- [try-to-tape](https://github.com/coderaiser/try-to-tape) - `try catch` for async tape tests\n- [try-catch](https://github.com/coderaiser/try-catch \"TryCatch\") - functional try-catch wrapper.\n- [try-to-catch](https://github.com/coderaiser/try-to-catch \"TryToCatch\") - functional try-catch wrapper for promises.\n\n## License\n\nMIT\n","publish_time":1632423232565,"_cnpm_publish_time":1632423232565,"dist-tags":{"latest":"5.1.0"}}