Skip to content

Commit

Permalink
Merge pull request #1319 from gitKrystan/expose-options-types
Browse files Browse the repository at this point in the history
Expose options types for setupContext and teardownContext
  • Loading branch information
chriskrycho authored Jan 19, 2023
2 parents de58ed3 + ecb6c6c commit 15ea6ab
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 2 additions & 0 deletions addon-test-support/@ember/test-helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type {
DeprecationFailure,
TestContext,
Warning,
SetupContextOptions,
} from './setup-context';
export {
default as setupContext,
Expand All @@ -25,6 +26,7 @@ export {
getWarningsDuringCallback,
} from './setup-context';
export { default as teardownContext } from './teardown-context';
export type { TeardownContextOptions } from './teardown-context';
export {
default as setupRenderingContext,
render,
Expand Down
6 changes: 5 additions & 1 deletion addon-test-support/@ember/test-helpers/setup-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ import {
Warning,
} from './-internal/warnings';

export interface SetupContextOptions {
resolver?: Resolver | undefined;
}

// This handler exists to provide the underlying data to enable the following methods:
// * getDeprecations()
// * getDeprecationsDuringCallback()
Expand Down Expand Up @@ -374,7 +378,7 @@ export const SetUsage = new WeakMap<BaseContext, Array<string>>();
*/
export default function setupContext<T extends object>(
base: T,
options: { resolver?: Resolver } = {}
options: SetupContextOptions = {}
): Promise<T & TestContext> {
let context = base as T & TestContext;

Expand Down
11 changes: 5 additions & 6 deletions addon-test-support/@ember/test-helpers/teardown-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import settled from './settled';
import { _cleanupOnerror } from './setup-onerror';
import { destroy } from '@ember/destroyable';

export interface TeardownContextOptions {
waitForSettled?: boolean | undefined;
}

/**
Used by test framework addons to tear down the provided context after testing is completed.
Expand All @@ -20,13 +24,8 @@ import { destroy } from '@ember/destroyable';
*/
export default function teardownContext(
context: TestContext,
options?: { waitForSettled?: boolean }
{ waitForSettled = true }: TeardownContextOptions = {}
): Promise<void> {
let waitForSettled = true;
if (options !== undefined && 'waitForSettled' in options) {
waitForSettled = options.waitForSettled!;
}

return Promise.resolve()
.then(() => {
_cleanupOnerror(context);
Expand Down

0 comments on commit 15ea6ab

Please sign in to comment.