{"_id":"testdouble-jest","_rev":"8-b255372151bacf3619a114fbde94e5ff","name":"testdouble-jest","dist-tags":{"latest":"2.0.0"},"versions":{"1.0.0":{"name":"testdouble-jest","version":"1.0.0","keywords":["testdouble","jest","mock"],"author":{"name":"Justin Searls","email":"searls@gmail.com"},"license":"MIT","_id":"testdouble-jest@1.0.0","maintainers":[{"name":"searls","email":"searls@gmail.com"}],"homepage":"https://github.com/testdouble/testdouble-jest#readme","bugs":{"url":"https://github.com/testdouble/testdouble-jest/issues"},"dist":{"shasum":"4d771ae475880df71a592fe632c854a2d5bc9751","tarball":"https://registry.npmjs.org/testdouble-jest/-/testdouble-jest-1.0.0.tgz","fileCount":9,"integrity":"sha512-H3eORwriFB36XVf8SuKCR5FGI1IC+p8rvRd46Uvx0r2pcjWYOEQKYM6Y5361ABGd49DK1aGhfD9bFaydHKs0mQ==","signatures":[{"sig":"MEUCIQDjif9xnxxpOLsHEQJ3zhDxkY5KZ9CRW6vFC12qc6SHagIgc8s8BWITo4F+zLye99dgTcSlp7ul8/WXpK9oYQMxTDw=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":6234},"main":"index.js","gitHead":"ea7fa3def1bb1c958a7c0704bfc8054432bc1f90","scripts":{"test":"cd example && npm it"},"_npmUser":{"name":"searls","email":"searls@gmail.com"},"repository":{"url":"git+https://github.com/testdouble/testdouble-jest.git","type":"git"},"_npmVersion":"5.6.0","description":"testdouble.js extension to add support for Jest module mocking","directories":{},"_nodeVersion":"8.9.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/testdouble-jest_1.0.0_1518300353193_0.09726399923424989","host":"s3://npm-registry-packages"}},"1.0.1":{"name":"testdouble-jest","version":"1.0.1","keywords":["testdouble","jest","mock"],"author":{"name":"Justin Searls","email":"searls@gmail.com"},"license":"MIT","_id":"testdouble-jest@1.0.1","maintainers":[{"name":"searls","email":"searls@gmail.com"}],"homepage":"https://github.com/testdouble/testdouble-jest#readme","bugs":{"url":"https://github.com/testdouble/testdouble-jest/issues"},"dist":{"shasum":"7efd2e1d290ede5e89092b97e9d36034fc6870b6","tarball":"https://registry.npmjs.org/testdouble-jest/-/testdouble-jest-1.0.1.tgz","fileCount":11,"integrity":"sha512-KDMCOyeIjz5dg1RkTOMblFCDGtXYQyumUSqoaXYkp1aVbP9Fu8wDtxmwfH5wuap8Ldw9LMK0YtK1DD+34Ycrqw==","signatures":[{"sig":"MEQCIA3jQ9GacHdBb04jruZQb+Ai4kZgcpexnHN9fiWs6rGLAiAS3cxbs6Tq36rKhMNssjBaCNx0En9OK9Q/5ASalo5/4g==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":8582},"main":"index.js","gitHead":"b3b7701950e6b4af3372adb8941b266cff5390a7","scripts":{"test":"cd example && npm it"},"_npmUser":{"name":"searls","email":"searls@gmail.com"},"repository":{"url":"git+https://github.com/testdouble/testdouble-jest.git","type":"git"},"_npmVersion":"5.6.0","description":"testdouble.js extension to add support for Jest module mocking","directories":{},"_nodeVersion":"8.9.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/testdouble-jest_1.0.1_1518357640965_0.7294574746251732","host":"s3://npm-registry-packages"}},"2.0.0":{"name":"testdouble-jest","version":"2.0.0","keywords":["testdouble","jest","mock"],"author":{"name":"Justin Searls","email":"searls@gmail.com"},"license":"MIT","_id":"testdouble-jest@2.0.0","maintainers":[{"name":"searls","email":"searls@gmail.com"}],"homepage":"https://github.com/testdouble/testdouble-jest#readme","bugs":{"url":"https://github.com/testdouble/testdouble-jest/issues"},"dist":{"shasum":"e5f48ae2978e386638e1eeeb6335e52093ac6071","tarball":"https://registry.npmjs.org/testdouble-jest/-/testdouble-jest-2.0.0.tgz","fileCount":11,"integrity":"sha512-+Ny3/ZtLcPBXZaVdLXYDDmZtCe5Erx/Rr8scLisFSHR763eHIEh4dGrISfENc+ezvhMLH1GvgSpZjagdv6l3yQ==","signatures":[{"sig":"MEYCIQDrzVlHzzDJ2rV8YuP9+mRq/NJO+FR6Ov/vOTnrw/lpkAIhAMOC5duKOE1bgANcYFqycq4whyzOO2WmM0XCEfbMxdHb","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":8927},"main":"index.js","gitHead":"e9f2ee1dab60e71f96299c1fec2a0630a2d17104","scripts":{"test":"cd example && npm it"},"_npmUser":{"name":"searls","email":"searls@gmail.com"},"repository":{"url":"git+https://github.com/testdouble/testdouble-jest.git","type":"git"},"_npmVersion":"5.7.1","description":"testdouble.js extension to add support for Jest module mocking","directories":{},"_nodeVersion":"8.9.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/testdouble-jest_2.0.0_1521903877170_0.7341749966336018","host":"s3://npm-registry-packages"}}},"time":{"created":"2018-02-10T22:05:53.193Z","modified":"2026-09-21T16:42:10.386Z","1.0.0":"2018-02-10T22:05:54.921Z","1.0.1":"2018-02-11T14:00:41.569Z","2.0.0":"2018-03-24T15:04:37.245Z"},"bugs":{"url":"https://github.com/testdouble/testdouble-jest/issues"},"author":{"name":"Justin Searls","email":"searls@gmail.com"},"license":"MIT","homepage":"https://github.com/testdouble/testdouble-jest#readme","keywords":["testdouble","jest","mock"],"repository":{"url":"git+https://github.com/testdouble/testdouble-jest.git","type":"git"},"description":"testdouble.js extension to add support for Jest module mocking","maintainers":[{"email":"dustin@testdouble.com","name":"dustin.tinney"},{"email":"mike@testdouble.com","name":"mike.testdouble"},{"email":"ross.brandes@gmail.com","name":"rosston"},{"email":"searls@gmail.com","name":"searls"}],"readme":"# testdouble-jest\n\nSupport for [testdouble.js](https://github.com/testdouble/testdouble.js) for\nusers of [Jest](https://github.com/facebook/jest)!\n\nNote that testdouble-jest requires testdouble@3.6.0 or higher to work.\n\n## Installation\n\n```\n$ npm i -D testdouble-jest\n```\n\nThen, from a test helper (we recommend setting a\n[setupTestFrameworkScriptFile](https://facebook.github.io/jest/docs/en/configuration.html#setuptestframeworkscriptfile-string)\nmodule), invoke the module and pass in both `td` and `jest`, like so:\n\n```js\nglobal.td = require('testdouble')\nrequire('testdouble-jest')(td, jest)\n```\n\nFor an example of a helper that sets up testdouble.js, testdouble-jest, and\nensures `td.reset()` is called after each test, look at\n[example/helper.js](/example/helper.js) in this repo.\n\n## Usage\n\nWhen you invoke `testdouble-jest`, it does two things: (1) adds support for\nusing `td.replace()` for module replacement in Jest tests, and (2) adds a new\ntop-level `td.mock()` function that mirrors the `jest.mock()` API.\n\nWe recommend using `td.replace()`, since it's terser (by returning the fake\ninstead of the `jest` object) and your use of testdouble.js will remain portable\neven if you were to move to a different test runner.\n\n**`td.replace(moduleName[, manualStub])`**\n\nOnce you've initialized testdouble-jest in your test run, `td.replace()` will be\nable to replace modules just as it does in any other test runner. Functionally,\nit's delegates to `td.mock()`, but behaves just as it [always\nhas](https://github.com/testdouble/testdouble.js#module-replacement-with-nodejs)\nfor module replacement.\n\nHere's a trivial example:\n\n```js\nlet loadInvoices, subject\ndescribe('td.replace', () => {\n  beforeEach(() => {\n    loadInvoices = td.replace('./load-invoices')\n    subject = require('./calculate-payment')\n  })\n  it('calculates payments', () => {\n    td.when(loadInvoices(2018, 7)).thenReturn([24,28])\n\n    const result = subject('2018-07')\n\n    expect(result).toEqual(52)\n  })\n})\n```\n\nFor a runnable example, check\n[example/td-replace.test.js](/example/td-replace.test.js).\n\n**`td.mock(moduleName[, moduleFactory, options])`**\n\n`td.mock()` is designed to have the same API as\n[`jest.mock()`](https://facebook.github.io/jest/docs/en/es6-class-mocks.html).\nIf you just pass a module name to `td.mock()`, it will imitate the real\ndependency and use Jest's own module replacement facility to ensure that any\n`require()` calls by your test subject receive the testdouble fake, as opposed\nto the real dependency. There's an example in this repo at\n[example/td-mock.test.js](/example/td-mock.test.js).\n\nIf you've used `jest.mock()` before, `td.mock()` will seem pretty familiar.\n`td.mock()` retruns the `jest` object (since that's what\n`jest.mock()` does), so your test will also need to `require()` the thing you\njust faked if you want to set up any stubbings or invocation assertions.\n\nNote that if you provide a `moduleFactory` and/or `options` argument, `td.mock`\nwill simply delegate to `jest.mock`, since it won't have anything\ntestdouble.js-specific to do.\n","readmeFilename":"README.md"}