Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose options types for setupContext and teardownContext #1319

Merged
merged 1 commit into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -372,7 +376,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