{"name":"@cloudcmd/stub","version":"5.1.0","type":"module","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/cloudcmd/stub","main":"lib/stub.js","repository":{"type":"git","url":"git+https://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":{"jest-diff":"^30.2.0"},"keywords":["sinon","stub","async","promise","calledWith","diff","tape"],"devDependencies":{"check-dts":"^1.0.0","coveralls":"^3.0.0","eslint":"^10.7.0","eslint-plugin-node":"^11.0.0","eslint-plugin-putout":"^31.4.1","madrun":"^13.0.3","nodemon":"^3.1.11","putout":"^42.9.0","redrun":"^13.0.0","superc8":"^12.7.0","supertape":"^13.4.2","try-catch":"^4.0.7","try-to-catch":"^4.0.3"},"license":"MIT","engines":{"node":">=22"},"publishConfig":{"access":"public"},"_id":"@cloudcmd/stub@5.1.0","gitHead":"193a2964ea08dedb2c80e8ca5580a83aad201208","types":"./lib/stub.d.ts","bugs":{"url":"https://github.com/cloudcmd/stub/issues"},"_nodeVersion":"26.5.0","_npmVersion":"11.4.2","dist":{"integrity":"sha512-rBwY4C5wdc74/uYYL7d1CKycC4oj7QRdqVbY1zIQF5XJbCYuW8/q+peBZxsFYzf9xM5n+IP0OxEjpB+HoNXKyA==","shasum":"9a28d8f37cd8026bea58568696b7be7f684f2079","tarball":"http://registry-npm.ywwl.com/@cloudcmd/stub/download/@cloudcmd/stub-5.1.0.tgz","fileCount":7,"unpackedSize":12977,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIGL8JPdGluGviWoYpuSOk69Q49LN3yv/RM2cPHsMajssAiEA2vCMEXbIYuJVHqgEu6He81unVTsBt/Lm5ie6eg8aHnY="}],"size":4571,"noattachment":false,"key":"/@cloudcmd/stub/-/@cloudcmd/stub-5.1.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-npm-production","tmp":"tmp/stub_5.1.0_1783932679617_0.36596308774723374"},"_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\nimport {stub} from '@cloudcmd/stub';\n\nconst fn = stub();\n\n// fn contains stubbed function\nconst asyncFn = stub(async () => {\n    throw Error('hi');\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\n// throws\nError('hello');\n```\n\n### stub().rejects([error])\n\n```js\nconst fn = stub().rejects(Error('hello'));\nawait fn();\n\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\n// returns\n0;\n\nfn();\n\nfn.callCount;\n\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[\n    [1],\n];\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\n// returns\n1;\n\nfn2.callId;\n\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":1783932679763,"_cnpm_publish_time":1783932679763,"dist-tags":{"latest":"5.1.0"}}