{"_id":"@async-fn/vitest","_rev":"3-6811817e81543cd5f1879aa06f969351","name":"@async-fn/vitest","dist-tags":{"latest":"1.8.0"},"versions":{"1.6.5":{"name":"@async-fn/vitest","version":"1.6.5","keywords":["vitest","async-testing","unit-testing","mock","mocking","test","testing","tdd","bdd","asynchronous"],"author":{"name":"Team: Igniter from Houston Inc. Consulting"},"license":"MIT","_id":"@async-fn/vitest@1.6.5","maintainers":[{"name":"jansav","email":"janne.savolainen@live.fi"},{"name":"iku-turso","email":"mikko.aspiala@gmail.com"}],"homepage":"https://github.com/team-igniter-from-houston-inc/async-fn#readme","bugs":{"url":"https://github.com/team-igniter-from-houston-inc/async-fn/issues"},"dist":{"shasum":"b2aadb3118857327535df4378adc0b799c5732e4","tarball":"https://registry.npmjs.org/@async-fn/vitest/-/vitest-1.6.5.tgz","fileCount":10,"integrity":"sha512-mK4NIou8cWtIc5x+Vk12RxddCdPcenJHDw0kqXMAyL0o4yWTcowuPHb0NyOOf09cGWYbwFw/7S309talzMVBaw==","signatures":[{"sig":"MEUCIGG1nsRMSqIraBociSN+6h+JqXF8sWKWTziAmTwONy5yAiEA9hR6mgWdpXhjiEJ1Q3u0uDcL/cpQ3ToLcsJShH0QtX8=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":59509},"main":"build/index.mjs","type":"module","types":"./src/asyncFnForVitest.d.ts","module":"build/index.mjs","exports":{".":{"import":"./build/index.mjs","default":"./build/index.mjs"}},"gitHead":"3561db8577a347f7b5b147499fe8fa50524b4e13","scripts":{"test":"vitest run","build":"webpack --config=./webpack.config.cjs"},"_npmUser":{"name":"jansav","email":"janne.savolainen@live.fi"},"repository":{"url":"git+https://github.com/team-igniter-from-houston-inc/async-fn.git","type":"git"},"_npmVersion":"lerna/5.6.2/node@v24.11.1+arm64 (darwin)","description":"Additional methods to vi.fn to introduce \"late resolve\" of promises returned by mock functions. This allows tests that read chronologically, like a story.","directories":{},"_nodeVersion":"24.11.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"@async-fn/core":"^1.6.5"},"peerDependencies":{"vitest":">= 1.0.0"},"_npmOperationalInternal":{"tmp":"tmp/vitest_1.6.5_1771959510445_0.7419547163555791","host":"s3://npm-registry-packages-npm-production"}},"1.7.0":{"name":"@async-fn/vitest","version":"1.7.0","keywords":["vitest","async-testing","unit-testing","mock","mocking","test","testing","tdd","bdd","asynchronous"],"author":{"name":"Team: Igniter from Houston Inc. Consulting"},"license":"MIT","_id":"@async-fn/vitest@1.7.0","maintainers":[{"name":"jansav","email":"janne.savolainen@live.fi"},{"name":"iku-turso","email":"mikko.aspiala@gmail.com"}],"homepage":"https://github.com/team-igniter-from-houston-inc/async-fn#readme","bugs":{"url":"https://github.com/team-igniter-from-houston-inc/async-fn/issues"},"dist":{"shasum":"85f9aaabc0ee12f5039ed11a290a56ce1adecf2a","tarball":"https://registry.npmjs.org/@async-fn/vitest/-/vitest-1.7.0.tgz","fileCount":12,"integrity":"sha512-3aebNCG1Wgn7UOCwqjflHC+ZVtPCNwF7EjOdhqX9iBGnzbXTQNV+qadc1CW/T9CmIlt54JI2OEd91mKKbv0u9g==","signatures":[{"sig":"MEQCIDuYvWwpPTH8AkKK2LslGbMi6Yh6UB9gWSFWWtFN3pYIAiAauRjUnUfS0NagfWwd0yebRtBIEYi8g5lTCO8mLNr1sA==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":63620},"main":"build/index.mjs","type":"module","types":"./src/asyncFnForVitest.d.ts","module":"build/index.mjs","exports":{".":{"types":"./src/asyncFnForVitest.d.ts","import":"./build/index.mjs","default":"./build/index.mjs"}},"gitHead":"536260e4337562a27cb1361d8fa3fc5dc83c9a93","scripts":{"test":"vitest run","build":"webpack --config=./webpack.config.cjs"},"_npmUser":{"name":"iku-turso","email":"mikko.aspiala@gmail.com"},"repository":{"url":"git+https://github.com/team-igniter-from-houston-inc/async-fn.git","type":"git"},"_npmVersion":"lerna/9.0.7/node@v22.14.0+arm64 (darwin)","description":"Additional methods to vi.fn to introduce \"late resolve\" of promises returned by mock functions. This allows tests that read chronologically, like a story.","directories":{},"_nodeVersion":"22.14.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"@async-fn/core":"^1.7.0"},"peerDependencies":{"vitest":">= 1.0.0"},"_npmOperationalInternal":{"tmp":"tmp/vitest_1.7.0_1777204070368_0.03454811069088093","host":"s3://npm-registry-packages-npm-production"}},"1.8.0":{"name":"@async-fn/vitest","version":"1.8.0","description":"Additional methods to vi.fn to introduce \"late resolve\" of promises returned by mock functions. This allows tests that read chronologically, like a story.","main":"build/index.mjs","module":"build/index.mjs","type":"module","exports":{".":{"types":"./src/asyncFnForVitest.d.ts","import":"./build/index.mjs","default":"./build/index.mjs"}},"types":"./src/asyncFnForVitest.d.ts","repository":{"type":"git","url":"git+https://github.com/team-igniter-from-houston-inc/async-fn.git"},"keywords":["vitest","async-testing","unit-testing","mock","mocking","test","testing","tdd","bdd","asynchronous"],"author":{"name":"Team: Igniter from Houston Inc. Consulting"},"license":"MIT","scripts":{"build":"webpack --config=./webpack.config.cjs","test":"vitest run"},"devDependencies":{"@async-fn/core":"^1.8.0"},"peerDependencies":{"vitest":">= 4.0.0"},"publishConfig":{"access":"public"},"gitHead":"225950de9b78aa4e1a8c137a5838aa355a279f09","_id":"@async-fn/vitest@1.8.0","bugs":{"url":"https://github.com/team-igniter-from-houston-inc/async-fn/issues"},"homepage":"https://github.com/team-igniter-from-houston-inc/async-fn#readme","_nodeVersion":"22.14.0","_npmVersion":"lerna/9.0.7/node@v22.14.0+arm64 (darwin)","dist":{"integrity":"sha512-8kM8y3SY7ogjLtnBaXCu5TKASTsZ1bOhJJiY+b+1pFMPypYgsXVIO8lPMyj28ZdiGbHJS8CCj2UY7HI3RlsMYw==","shasum":"0135c036ef712397462fb06e7788a447c306104b","tarball":"https://registry.npmjs.org/@async-fn/vitest/-/vitest-1.8.0.tgz","fileCount":15,"unpackedSize":65591,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIDlNcxZ+HrNmeYWywYA7xFCIjZ1dWCiXaPsy4cRUKrXhAiAmzq+ttLKD9lMUSaD5gBwWS6qk7Ath+VfaGXcOEAEdZA=="}]},"_npmUser":{"name":"iku-turso","email":"mikko.aspiala@gmail.com"},"directories":{},"maintainers":[{"name":"jansav","email":"janne.savolainen@live.fi"},{"name":"iku-turso","email":"mikko.aspiala@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/vitest_1.8.0_1777874408030_0.4649369062580848"},"_hasShrinkwrap":false}},"time":{"created":"2026-02-24T18:58:29.834Z","modified":"2026-05-04T06:00:08.346Z","1.6.5":"2026-02-24T18:58:30.586Z","1.7.0":"2026-04-26T11:47:50.522Z","1.8.0":"2026-05-04T06:00:08.166Z"},"bugs":{"url":"https://github.com/team-igniter-from-houston-inc/async-fn/issues"},"author":{"name":"Team: Igniter from Houston Inc. Consulting"},"license":"MIT","homepage":"https://github.com/team-igniter-from-houston-inc/async-fn#readme","keywords":["vitest","async-testing","unit-testing","mock","mocking","test","testing","tdd","bdd","asynchronous"],"repository":{"type":"git","url":"git+https://github.com/team-igniter-from-houston-inc/async-fn.git"},"description":"Additional methods to vi.fn to introduce \"late resolve\" of promises returned by mock functions. This allows tests that read chronologically, like a story.","maintainers":[{"name":"jansav","email":"janne.savolainen@live.fi"},{"name":"iku-turso","email":"mikko.aspiala@gmail.com"}],"readme":"# @async-fn/vitest\n\n**asyncFn** for vitest provides additional methods to vi.fn to introduce \"**late resolve**\" for the promises returned.\n\nThis simplifies async unit testing by allowing tests that read chronologically, **like a story**, and do not require excessive test setup to know beforehand how async mocks are supposed to behave in each scenario.\n\n## How to install\n\n```\n$ npm install --save-dev @async-fn/vitest\n```\n\nIn your `vitest.config.js` ensure that you have the following configuration. This is required when using `vi.mock(<some-module>)`.\n\n```js\nexport default defineConfig({\n  test: {\n    clearMocks: true,\n  }\n})\n```\n\n## Examples\n\n### Late resolve for calls to a mock to make tests read like a story\n\n```javascript\nimport asyncFn from '@async-fn/vitest';\n\nit('given called, a result can be resolved *after* the mock is called', async () => {\n  const mockFunction = asyncFn();\n  const promise = mockFunction();\n\n  // Note how we resolve the returned promise *after* it is called.\n  // This permits us to write our tests so that they read like a story.\n  await mockFunction.resolve('some-value');\n\n  const actual = await promise;\n  expect(actual).toBe('some-value');\n});\n```\n\n### Late resolve for multiple calls to a mock\n\n```javascript\nimport asyncFn from '@async-fn/vitest';\n\nit('given called multiple times, the results can be resolved *after* the mock was called', async () => {\n  const mockFunction = asyncFn();\n\n  const promise = Promise.all([mockFunction(), mockFunction(), mockFunction()]);\n\n  await mockFunction.resolve('some-first-value');\n  await mockFunction.resolve('some-second-value');\n  await mockFunction.resolve('some-third-value');\n\n  const actual = await promise;\n\n  expect(actual).toEqual([\n    'some-first-value',\n    'some-second-value',\n    'some-third-value',\n  ]);\n});\n```\n\n### Late rejection\n\n```javascript\nimport asyncFn from '@async-fn/vitest';\n\nit('can be rejected with a rejection', () => {\n  const mockFunction = asyncFn();\n  const promise = mockFunction();\n\n  mockFunction.reject('some-rejection');\n\n  return expect(promise).rejects.toBe('some-rejection');\n});\n```\n\n### The other stuff vi.fn does\n\n```javascript\nimport asyncFn from '@async-fn/vitest';\n\nit('does what vi.fn does', () => {\n  const mockFunction = asyncFn();\n\n  mockFunction('some-argument', 'some-other-argument');\n\n  expect(mockFunction).toHaveBeenCalledWith(\n    'some-argument',\n    'some-other-argument',\n  );\n});\n```\n\n## More examples\n\nCheck out the [unit tests](https://github.com/team-igniter-from-houston-inc/async-fn/blob/master/packages/core/test-utils/itWorksAsAsyncFn.js).\n\n## Availability\n\nasyncFn is also available for [jest](https://www.npmjs.com/package/@async-fn/jest) and [sinon](https://www.npmjs.com/package/@async-fn/sinon).\n","readmeFilename":"README.md"}