import type { Resolver } from '@ember/owner'; import { Owner } from './build-owner'; import { DeprecationFailure } from './-internal/deprecations'; import { Warning } from './-internal/warnings'; export interface SetupContextOptions { resolver?: Resolver | undefined; } export type BaseContext = object; /** * The public API for the test context, which test authors can depend on being * available. * * Note: this is *not* user-constructible; it becomes available by calling * `setupContext()` with a base context object. */ export interface TestContext extends BaseContext { owner: Owner; set(key: string, value: T): T; setProperties>(hash: T): T; get(key: string): unknown; getProperties(...args: string[]): Record; pauseTest(): Promise; resumeTest(): void; } export declare function isTestContext(context: BaseContext): context is TestContext; /** Stores the provided context as the "global testing context". Generally setup automatically by `setupContext`. @public @param {Object} context the context to use */ export declare function setContext(context: BaseContext): void; /** Retrieve the "global testing context" as stored by `setContext`. @public @returns {Object} the previously stored testing context */ export declare function getContext(): BaseContext | undefined; /** Clear the "global testing context". Generally invoked from `teardownContext`. @public */ export declare function unsetContext(): void; /** * Returns a promise to be used to pauses the current test (due to being * returned from the test itself). This is useful for debugging while testing * or for test-driving. It allows you to inspect the state of your application * at any point. * * The test framework wrapper (e.g. `ember-qunit` or `ember-mocha`) should * ensure that when `pauseTest()` is used, any framework specific test timeouts * are disabled. * * @public * @returns {Promise} resolves _only_ when `resumeTest()` is invoked * @example Usage via ember-qunit * * import { setupRenderingTest } from 'ember-qunit'; * import { render, click, pauseTest } from '@ember/test-helpers'; * * * module('awesome-sauce', function(hooks) { * setupRenderingTest(hooks); * * test('does something awesome', async function(assert) { * await render(hbs`{{awesome-sauce}}`); * * // added here to visualize / interact with the DOM prior * // to the interaction below * await pauseTest(); * * click('.some-selector'); * * assert.equal(this.element.textContent, 'this sauce is awesome!'); * }); * }); */ export declare function pauseTest(): Promise; /** Resumes a test previously paused by `await pauseTest()`. @public */ export declare function resumeTest(): void; /** * Returns deprecations which have occurred so far for a the current test context * * @public * @returns {Array} An array of deprecation messages * @example Usage via ember-qunit * * import { getDeprecations } from '@ember/test-helpers'; * * module('awesome-sauce', function(hooks) { * setupRenderingTest(hooks); * * test('does something awesome', function(assert) { const deprecations = getDeprecations() // => returns deprecations which have occurred so far in this test * }); * }); */ export declare function getDeprecations(): Array; export type { DeprecationFailure }; /** * Returns deprecations which have occurred so far for a the current test context * * @public * @param {Function} [callback] The callback that when executed will have its DeprecationFailure recorded * @returns {Array | Promise>} An array of deprecation messages * @example Usage via ember-qunit * * import { getDeprecationsDuringCallback } from '@ember/test-helpers'; * * module('awesome-sauce', function(hooks) { * setupRenderingTest(hooks); * * test('does something awesome', function(assert) { * const deprecations = getDeprecationsDuringCallback(() => { * // code that might emit some deprecations * * }); // => returns deprecations which occurred while the callback was invoked * }); * * * test('does something awesome', async function(assert) { * const deprecations = await getDeprecationsDuringCallback(async () => { * // awaited code that might emit some deprecations * }); // => returns deprecations which occurred while the callback was invoked * }); * }); */ export declare function getDeprecationsDuringCallback(callback: () => void): Array | Promise>; /** * Returns warnings which have occurred so far for a the current test context * * @public * @returns {Array} An array of warnings * @example Usage via ember-qunit * * import { getWarnings } from '@ember/test-helpers'; * * module('awesome-sauce', function(hooks) { * setupRenderingTest(hooks); * * test('does something awesome', function(assert) { const warnings = getWarnings() // => returns warnings which have occurred so far in this test * }); * }); */ export declare function getWarnings(): Array; export type { Warning }; /** * Returns warnings which have occurred so far for a the current test context * * @public * @param {Function} [callback] The callback that when executed will have its warnings recorded * @returns {Array | Promise>} An array of warnings information * @example Usage via ember-qunit * * import { getWarningsDuringCallback } from '@ember/test-helpers'; * import { warn } from '@ember/debug'; * * module('awesome-sauce', function(hooks) { * setupRenderingTest(hooks); * * test('does something awesome', function(assert) { * const warnings = getWarningsDuringCallback(() => { * warn('some warning'); * * }); // => returns warnings which occurred while the callback was invoked * }); * * test('does something awesome', async function(assert) { * warn('some warning'); * * const warnings = await getWarningsDuringCallback(async () => { * warn('some other warning'); * }); // => returns warnings which occurred while the callback was invoked * }); * }); */ export declare function getWarningsDuringCallback(callback: () => void): Array | Promise>; export declare const ComponentRenderMap: WeakMap; export declare const SetUsage: WeakMap; /** Used by test framework addons to setup the provided context for testing. Responsible for: - sets the "global testing context" to the provided context (`setContext`) - create an owner object and set it on the provided context (e.g. `this.owner`) - setup `this.set`, `this.setProperties`, `this.get`, and `this.getProperties` to the provided context - setting up AJAX listeners - setting up `pauseTest` (also available as `this.pauseTest()`) and `resumeTest` helpers @public @param {Object} base the context to setup @param {Object} [options] options used to override defaults @param {Resolver} [options.resolver] a resolver to use for customizing normal resolution @returns {Promise} resolves with the context that was setup */ export default function setupContext(base: T, options?: SetupContextOptions): Promise; //# sourceMappingURL=setup-context.d.ts.map