{"_id":"@aesop-fables/containr-testing","_rev":"1-a28cd3da7898c0d1c843a0f7cef99b48","name":"@aesop-fables/containr-testing","dist-tags":{"latest":"0.3.0"},"versions":{"0.2.3":{"name":"@aesop-fables/containr-testing","version":"0.2.3","description":"Testing support (utilities, pattern examples) for containr","type":"commonjs","exports":{".":{"types":"./lib/index.d.ts","default":"./lib/index.js"}},"main":"./lib/index.js","types":"./lib/index.d.ts","scripts":{"build":"rimraf ./lib && tsc --p ./tsconfig.build.json","format":"prettier --write \"src/**/*.(js|ts)\"","lint":"eslint src --ext .js,.ts","lint:fix":"eslint src --fix --ext .js,.ts","test":"jest --config jest.config.js","prepublishOnly":"npm test && npm run lint","preversion":"npm run lint","version":"npm run format && git add -A src","postversion":"git push && git push --tags"},"devDependencies":{"@aesop-fables/containr":"^0.2.3","@types/jest":"^29.2.4","@types/node":"^18.11.11","@typescript-eslint/eslint-plugin":"^5.45.1","@typescript-eslint/parser":"5.45.0","esbuild":"^0.17.8","eslint":"8.34.0","eslint-config-prettier":"^8.5.0","eslint-plugin-jest":"27.1.6","eslint-plugin-prettier":"^4.2.1","jest":"29.3.1","prettier":"^2.8.1","ts-jest":"29.0.1","typescript":"4.9.3"},"dependencies":{"reflect-metadata":"^0.1.13"},"peerDependencies":{"@aesop-fables/containr":">= 0.2.2","jest-mock-extended":"3.x"},"gitHead":"5d93a8c6b3caba8dd737ea5de1e8852689aa0a92","_id":"@aesop-fables/containr-testing@0.2.3","_nodeVersion":"16.19.0","_npmVersion":"8.19.3","dist":{"integrity":"sha512-yE6ixEZKUK9rZVMMP3NCavmxt5nlhAaoZqCQV7PRGMwHfMzZbfCTugZTtw2jesjUG7pL5t3yCgtgRdFMe5OQ7Q==","shasum":"dd697b1a45462e0a1701e4d9cfbab16aad2c4c48","tarball":"https://registry.npmjs.org/@aesop-fables/containr-testing/-/containr-testing-0.2.3.tgz","fileCount":7,"unpackedSize":8435,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDueYEvjEO72Cc8+2SCC19IDF2RnGSoKMnGqDZLmfu1JwIhALDZnuayfk2S1U6i/sBYDaf+duSmETDy68tdo5KciMbP"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj663/ACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmr7rxAAj/0G1kt0wmrdk+sxXvEUryE21DP6GPaXH+lJQpp+rtyqbisZ\r\n5J8oGZVHOu659TqNz5Cfih4QGS4DHeWxvv2jT8IU+ZA7x2/C6ZYJfLVDDLAy\r\nvO7UVp5egW6rEAkyIbhBoEXVTJieoEgPzrpcnqPdzf2m1RnTtJsMQjDCsGbx\r\nVI8UD0RgA0hISZcXwktvFmgb68CUNpG57PY9tXjcr7qwYLovQd9l31PwuoCR\r\nIjJfqDPwZtRDw3Evsl7Vpa0hfZtJ/j6hyV4VDhsImajDiw93om1InU1J7Q8j\r\nDsP4f+U0X6yipsy31Veczqsw7V4JawLMOmglRylcPYu2myxCwidPszhrwPtp\r\nSx/me3ikywyQgovpFtMRC0PfNtQwENJTmd6Gjvn7FiTeku86pCtdq6vm/YrS\r\nrPs5cHf2W+rnGEKsxQWoqGlWHcwZgrqDglK4wvLKPis5T7kr3LQuUwgavF3+\r\nTwwSNMOmXlXUZccadFj2PWCxH+tI5O99qH9pRGuP+RYNmQJWQ9IG7bolscIr\r\nqKAmZYwdy1kBbAm32vHGewYNp/paQdrUvnX1+ZwXcnC+jmsW3FesLmuEeluC\r\n7XHUJTGXH0BUHo74OsfF64h0QLBJiI/eQCFcgeV1CmnA981sqN6Jcv8N7Lrd\r\nt0WSv7r7LfxsQJQe7cN+bshcFGvfWo9Ier4=\r\n=I7/X\r\n-----END PGP SIGNATURE-----\r\n"},"_npmUser":{"name":"jmarnoldsan","email":"rncodepoet@gmail.com"},"directories":{},"maintainers":[{"name":"barretts","email":"barrett@sosuke.com"},{"name":"jmarnoldsan","email":"rncodepoet@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/containr-testing_0.2.3_1676389887653_0.8827128822749342"},"_hasShrinkwrap":false},"0.3.0":{"name":"@aesop-fables/containr-testing","version":"0.3.0","description":"Testing support (utilities, pattern examples) for containr","type":"commonjs","exports":{".":{"types":"./lib/index.d.ts","default":"./lib/index.js"}},"main":"./lib/index.js","types":"./lib/index.d.ts","scripts":{"build":"rimraf ./lib && tsc --p ./tsconfig.build.json","format":"prettier --write \"src/**/*.(js|ts)\"","lint":"eslint src --ext .js,.ts","lint:fix":"eslint src --fix --ext .js,.ts","test":"jest --config jest.config.js","prepublishOnly":"npm test && npm run lint","preversion":"npm run lint","version":"npm run format && git add -A src","postversion":"git push && git push --tags"},"devDependencies":{"@aesop-fables/containr":"^0.3.4","@types/jest":"^29.2.4","@types/node":"^18.11.11","@typescript-eslint/eslint-plugin":"^5.45.1","@typescript-eslint/parser":"5.45.0","esbuild":"^0.17.8","eslint":"8.34.0","eslint-config-prettier":"^8.5.0","eslint-plugin-jest":"27.1.6","eslint-plugin-prettier":"^4.2.1","jest":"29.3.1","prettier":"^2.8.1","ts-jest":"29.0.1","typescript":"4.9.3"},"dependencies":{"reflect-metadata":"^0.1.13"},"peerDependencies":{"@aesop-fables/containr":">= 0.3.2","jest-mock-extended":"3.x"},"gitHead":"872949877aefc830777766240cef2f2cbf60652d","_id":"@aesop-fables/containr-testing@0.3.0","_nodeVersion":"16.20.0","_npmVersion":"8.19.4","dist":{"integrity":"sha512-hdqAZx24VovKBLxxJMgpXA/n/Uv2nLFbeCsqgqids/MR8uKB0YMGLJ0JDFoKSG1KznlVFSd4xikHe5N0Q0ViuQ==","shasum":"efe2f8d40c9af1d29eec31751ff458af222025bc","tarball":"https://registry.npmjs.org/@aesop-fables/containr-testing/-/containr-testing-0.3.0.tgz","fileCount":7,"unpackedSize":8441,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDF3XkzHRY8/uKjlhskkfZbeSqqQP/meBtTPqzWndLy4wIgPsVF2BI9xwromFBFEp7uI0iKu8y6D6UnfwPC6sgZyig="}]},"_npmUser":{"name":"jmarnoldsan","email":"rncodepoet@gmail.com"},"directories":{},"maintainers":[{"name":"barretts","email":"barrett@sosuke.com"},{"name":"jmarnoldsan","email":"rncodepoet@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/containr-testing_0.3.0_1686254555365_0.9434198746007596"},"_hasShrinkwrap":false}},"time":{"created":"2023-02-14T15:51:27.544Z","0.2.3":"2023-02-14T15:51:27.857Z","modified":"2023-06-08T20:02:35.741Z","0.3.0":"2023-06-08T20:02:35.620Z"},"maintainers":[{"name":"barretts","email":"barrett@sosuke.com"},{"name":"jmarnoldsan","email":"rncodepoet@gmail.com"}],"description":"Testing support (utilities, pattern examples) for containr","readme":"# @aesop-fables/containr-testing\n\n`containr-testing` provides testing support when using `containr` for development.\n\n## Installation\n```\nnpm install @aesop-fables/containr-testing\n```\n```\nyarn add @aesop-fables/containr-testing\n```\n\n## Example\nOne of the most common testing patterns (when using dependency injection) leverages mocks and/or stubs (we're generalizing quite a bit here). `containr-testing` provides the `InteractionContext<T>` class that allows you \nto automatically generate mocks for your dependencies using `jest-mock-extended`.\n\n```typescript\n// MyEntityService.ts\nimport { inject } from '@aesop-fables/containr';\n\nexport interface IEvent {\n    correlationId: string;\n}\n\nexport interface IEventPublisher {\n    publish(event: IEvent): Promise<void>;\n}\n\nexport const MyServices = {\n    Publisher: 'publisher',\n};\n\nexport class MyEntityService implements IEntityService {\n    constructor(\n        @inject(MyServices.Publisher) private readonly publisher: IEventPublisher,\n    ) {}\n\n    createEntity(name: string): Promise<void> {\n        const entity = {\n            id: 'you would probably generate this',\n            name,\n        };\n\n        await this.publisher.push({\n            correlationId: entity.id,\n        });\n    }\n}\n\n// MyEntityService.test.ts\nimport { IEventPublisher, MyEntityService, MyServices } from './MyEntityService';\nimport { createInteractionContext, InteractionContext } from '@aesop-fables/containr-testing';\n\ndescribe('InteractionContext example', () => {\n  let context: InteractionContext<MyEntityService>;\n\n  beforeEach(() => {\n    // This will automatically configured the context\n    context = createInteractionContext(MyEntityService);\n\n    // If you need to modify the underlying collection\n    // You can do it - only if you do it BEFORE you call `context.classUnderTest`\n\n    // Calls to `context.services` will reset the instance of classUnderTest as well as the underlying service container (if it's already been instantiated)\n  });\n\n  test('demo auto-mocking', async () => {\n    // classsUnderTest is lazily evaluated and is only instantiated once (the first time you call the property)\n    await context.classUnderTest.createEntity('Hello');\n\n    // the context allows you to retrieve the mocks\n    // You could obviously inspect the invocation and do more elaborate assertions\n    expect(context.mockFor<IEventPublisher>(MyServices.Publisher).publish).toBeCalledTimes(1);\n  });\n});\n\n\n```","readmeFilename":"README.md"}