{"name":"@cloudcmd/stub","version":"5.0.0","keywords":["sinon","stub","async","promise","calledWith","diff","tape"],"author":{"url":"https://github.com/coderaiser","name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"license":"MIT","_id":"@cloudcmd/stub@5.0.0","maintainers":[{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"}],"homepage":"http://github.com/cloudcmd/stub","bugs":{"url":"https://github.com/cloudcmd/stub/issues"},"dist":{"shasum":"880d70d11878aa4c03d781ad2a70dabf981332d3","tarball":"http://registry-npm.ywwl.com/@cloudcmd/stub/download/@cloudcmd/stub-5.0.0.tgz","fileCount":7,"integrity":"sha512-jLC05CmcvEKDFXWf95UZGgqyJePhP3kh6/5ZXm7BAB42hv72RIx9LsYMhqGXlPtXjShV5KioOHri6QGnWMzHwQ==","signatures":[{"sig":"MEUCIEoN0UsP4ktZlCA+QIGEuPHpXRdsGNiJfCy3SXadHd3OAiEA9Gm4oHmULRxqccK6d0klkxP+MAysaWv5JjNYL83CYpM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":12360,"size":4356,"noattachment":false,"key":"/@cloudcmd/stub/-/@cloudcmd/stub-5.0.0.tgz"},"main":"lib/stub.js","type":"module","types":"./lib/stub.d.ts","engines":{"node":">=22"},"gitHead":"de5567a40d2f1ce54ac68d45bfbbf1e5ad081db4","scripts":{"lint":"madrun lint","test":"madrun test","report":"madrun report","wisdom":"madrun wisdom","coverage":"madrun coverage","fix:lint":"madrun fix:lint","test:dts":"madrun test:dts","fresh:lint":"madrun fresh:lint","lint:fresh":"madrun lint:fresh","watch:test":"madrun watch:test"},"_npmUser":{"name":"coderaiser","email":"mnemonic.enemy@gmail.com"},"repository":{"url":"git+https://github.com/cloudcmd/stub.git","type":"git"},"_npmVersion":"11.4.2","description":"simplest sinon.stub alternative with diff support","directories":{},"_nodeVersion":"25.2.1","dependencies":{"jest-diff":"^30.2.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"c8":"^10.1.3","eslint":"^9.39.2","madrun":"^12.1.0","putout":"^41.7.0","redrun":"^13.0.0","nodemon":"^3.1.11","check-dts":"^0.9.0","coveralls":"^3.0.0","supertape":"^12.0.11","try-catch":"^4.0.7","try-to-catch":"^4.0.3","eslint-plugin-node":"^11.0.0","eslint-plugin-putout":"^29.4.0"},"_npmOperationalInternal":{"tmp":"tmp/stub_5.0.0_1768167929677_0.2758317037821201","host":"s3://npm-registry-packages-npm-production"},"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":1768167929844,"_cnpm_publish_time":1768167929844,"dist-tags":{"latest":"5.1.0"}}