TestContainer
Index
Constructors
Methods
Constructors
constructor
Returns TestContainer
Methods
staticcreate
To take over the Container for one test, replacing the factories you name.
Parameters
subjects: TestContainerSubjects
The subjects being mocked.
mocksis an array of objects, to override the default factories.- Use
metadata?: { [key: string]: string }to identify the factory being mocked. - Use
type: Constructable<T> | stringto identify the class being mocked. - Use
value: Tto provide the mocked value.
- Use
optionaloptions: TestContainerOptions
Options to configure TestContainer.
factoryTimeoutInMs?: numberis to override the default container timeout.force?: booleanperforms a complete container reset.
Returns Promise<Container>
staticreset
To destroy every factory in the Container. Because it destroys the whole Container and not only the mocks, it must always be called in your teardown block - otherwise the next test starts against a Container this test left behind.
Returns Promise<void>
An isolated Container for tests.
The Container is a process-wide singleton, which makes it awkward to mock. TestContainer solves that: create one in
beforeEach()and it takes over the Container for that test, letting you replace any factory with a stub.reset()inafterEach()puts it back.A test framework like Jest runs test files in parallel across cores, and the
it()blocks within a file serially. So a TestContainer never leaks into a test running in parallel.Functions/Container