{"name":"@cloudcmd/stub","version":"4.0.0","type":"commonjs","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.6.6","coveralls":"^3.0.0","eslint":"^8.12.0","eslint-plugin-node":"^11.0.0","eslint-plugin-putout":"^14.8.0","madrun":"^9.0.2","mock-require":"^3.0.2","nodemon":"^2.0.0","putout":"^25.14.0","supertape":"^7.2.1","try-catch":"^3.0.0","try-to-catch":"^3.0.0"},"license":"MIT","engines":{"node":">=16"},"publishConfig":{"access":"public"},"types":"./lib/stub.d.ts","gitHead":"db6c572ae88e9cdb31d083b368b0705ede3325ce","bugs":{"url":"https://github.com/cloudcmd/stub/issues"},"_id":"@cloudcmd/stub@4.0.0","_nodeVersion":"16.14.2","_npmVersion":"8.3.0","dist":{"integrity":"sha512-lkA9tfrFox5GsMfkIRMGH3GzxAnsdKwQZ2ZMZ2iqlSnhnruOj7Rm1mRpZIFLkw53Gt8wOWv9k5d0Kxf9gxoH8A==","shasum":"95686c1d6a2acf2dfd072370ba6a0648167779cd","tarball":"http://registry-npm.ywwl.com/@cloudcmd/stub/download/@cloudcmd/stub-4.0.0.tgz","fileCount":7,"unpackedSize":11703,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC+dMaVnVN2MyjgGNdS66rP/Sj68JRb0cgPCTQg0XyNjQIhAMc1ioIns0M5quDVkbxkZDj2k/wqXZoCNczqRD20qUUJ"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiTeeEACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqXVxAAlEbUK++WCtjeCzd2/b3jviP7f15qQVLq/fvOdTT7mdizR2SQ\r\nZDxXN4fLT5kQcxPkG8uiJibmvUJpE/SsocTZ0GFKJymAANmUENQHLtsZbe3f\r\n3swotcyO6FN6/km0M87nrmja5xY7gdiTn+bMGDCGUz/3HfksTSDyNI7cTlIU\r\ncUywOvR6fUFmHLrdR84DY2Esr3bwLhw6gpnOmgoPKZvZPFkDb5lG7dZ9pxOG\r\n3+Uxx4opqb36zzQFdBgBsD/fFy9mCXvBCtQZ+IqSZhYXgot0UG6Mya1rp9Y9\r\nXeb5s11aoZvZDeRqLzFnQ5R510IThBN9eT1hDmIZVWgRMYb7m29ueesuaS/2\r\nG3FNI5PyXQ2HqUbld55m8sIA/OPIEQg2nQTz6oXd/5jUloRUkdj6LHS8fFVR\r\nW7oqAZyfyuzYhT+U41QofRVhNtIaQDtplKQrK0hVaUsHEeR2731v2UFCjUFY\r\nOS+9h26LqpHQ9a0RZ5zbxRGQ2C3vUm8NvnzitbQ1/p4q8AJZlY6kPIqu6CM8\r\n2NEvOBbE+z5sNAzRMY51UFfABZmB0mrFN5jEsG1O63dtDgilELvOkDVuW/Rj\r\n2+QHexZNDImUHY5/aX4IG/2z1+HCKozzzCg9HAZD6li69kcLO4ay5BFXLLtT\r\nMH3eB8WjOYUfbE1SsOz5bt8EKVvWJ4k8jJc=\r\n=brLD\r\n-----END PGP SIGNATURE-----\r\n","size":4042,"noattachment":false,"key":"/@cloudcmd/stub/-/@cloudcmd/stub-4.0.0.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_4.0.0_1649272707863_0.3769090952385272"},"_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":1649272708029,"_cnpm_publish_time":1649272708029,"dist-tags":{"latest":"5.1.0"}}