import { RegisterContextual } from 'ava'; import { ContainerOptions, Container } from '../metal/container'; export interface ContainerOverrideConfig { [containerSpecifier: string]: true | any; } export interface UnitTestContext { unit: UnitTest; container: Container; lookup: typeof Container.prototype.lookup; subject(): Subject; inject(injections: { [specifier: string]: any; }): void; inject(name: string, value: any, options?: ContainerOptions): void; restore(...specifiers: string[]): void; } export interface UnitTestOptions { /** * If true, the container will be cleared before each test, with only your * supplied overrides present. If false, the container will be fully * populated with your app, and then your overrides applied on top of that. * * Defaults to true, and that is the recommended approach. Clearing the * container forces you to declare _all_ the dependencies of the module under * test in your unit test. If set to false, it's easy to produce leaky unit * tests that end up accidentally relying on container dependencies that you * forgot to properly mock or declare. */ clearContainer?: false; } /** * The AppUnitTest class represents an app unit test. Loads up the bundle and * lookups up the module under test. The bundle allows for multiple concurrent * tests while ensuring state is not shared across them. * * @package test * @since 0.1.0 */ export declare class UnitTest { protected _subject: string | (() => any); protected overrideConfig: ContainerOverrideConfig; /** * A helper method for setting up an app unit test. Adds beforeEach/afterEach * hooks to the ava test suite which will setup and teardown the unit test. * They also setup a test transaction and roll it back once the test is * finished (for the ORM adapters that support it), so your test data won't * pollute the database. * * It returns the Ava test interface, but it enforces serial execution. For * more details, check out * https://gist.github.com/davewasmer/cd8ac4fad5502e9ce5c8055b283f08cb * * @since 0.1.0 */ static setupTest(subject?: string | (() => Subject), overrides?: ContainerOverrideConfig, options?: UnitTestOptions): RegisterContextual & AdditionalContext>; /** * The container instance for this test suite */ container: Container; /** * A map of container values that should be setup prior to each test run. This * is derived from the ContainerOverrideConfig that is passed into the * UnitTest constructor - it's the "allowed world" for this unit test. * * Note: don't confuse this with `originalContainerValues`, which holds the * value of a container entry that was overwritten by a user's `inject()` * call. The `originalContainerValues` is there to allow users to restore an * injected entry mid-test if needed. This `startingContainerValues` property * is for setting up the container _before_ each test. */ protected startingContainerValues: { [specifier: string]: any; }; protected originalContainerValues: { [specific: string]: any; }; constructor(_subject: string | (() => any), overrideConfig: ContainerOverrideConfig, options?: UnitTestOptions); setup(context: UnitTestContext): Promise; /** * Takes the supplied override config, and updates the bundle container to * match it. * * @param overrideConfig Container overrides that should be used for this * test (see ContainerOverrideConfig) */ protected applyContainerOverrideConfig(overrideConfig: ContainerOverrideConfig, clearContainer: false | undefined): void; /** * Returns the subject of the test. Follows container lookup rules, i.e. if * the entry under test is a singleton, will return the singleton instance, * not the class. * * @since 0.1.0 */ subject(): Subject; /** * Overwrite an entry in the test application container. Use `restore()` to * restore the original container entry later. Can supply a single name and * value with options, or an object whose keys are specifiers and values are * the values to inject. * * @since 0.1.0 */ inject(injections: { [specifier: string]: any; }): void; inject(name: string, value: any, options?: ContainerOptions): void; /** * Restore the original container entry for an entry that was previously * overwritten by `inject()`. If no arguments are supplied, all injections * are restored. * * @since 0.1.0 */ restore(...specifiers: string[]): void; /** * Lookup all the ORM adapters, and give each one a chance to start a * transaction that will wrap a test, and be rolled back after */ startTestTransactions(): Promise; /** * Roll back any test transactions started at the beginning of the test */ rollbackTestTransactions(): Promise; teardown(): Promise; } declare const _default: typeof UnitTest.setupTest; export default _default;