diff --git a/data_structures/binary_search_tree_test.ts b/data_structures/binary_search_tree_test.ts index eed4c12fc934..ba48d4915899 100644 --- a/data_structures/binary_search_tree_test.ts +++ b/data_structures/binary_search_tree_test.ts @@ -7,17 +7,7 @@ import { } from "@std/assert"; import { BinarySearchTree } from "./binary_search_tree.ts"; import { ascend, descend } from "./comparators.ts"; - -class MyMath { - multiply(a: number, b: number): number { - return a * b; - } -} - -interface Container { - id: number; - values: number[]; -} +import { type Container, MyMath } from "./_test_utils.ts"; Deno.test("BinarySearchTree throws if compare is not a function", () => { assertThrows( diff --git a/testing/_test_helpers.ts b/testing/_test_helpers.ts index 12cb88e9ab5d..dbd67c921fbf 100644 --- a/testing/_test_helpers.ts +++ b/testing/_test_helpers.ts @@ -8,7 +8,7 @@ import { import { assertSpyCall, assertSpyCalls, type Spy, spy, stub } from "./mock.ts"; import { TestSuiteInternal } from "./_test_suite.ts"; -class TestContext implements Deno.TestContext { +export class TestContext implements Deno.TestContext { name: string; origin: string; steps: TestContext[]; diff --git a/testing/bdd_test.ts b/testing/bdd_test.ts index 1aefc5cb6c79..7ddfc985d3e2 100644 --- a/testing/bdd_test.ts +++ b/testing/bdd_test.ts @@ -19,59 +19,7 @@ import { } from "./bdd.ts"; import { TestSuiteInternal } from "./_test_suite.ts"; import { assertSpyCall, assertSpyCalls, type Spy, spy, stub } from "./mock.ts"; - -class TestContext implements Deno.TestContext { - name: string; - origin: string; - steps: TestContext[]; - spies: { - step: Spy; - }; - - constructor(name: string) { - this.name = name; - this.origin = "origin"; - this.spies = { - step: spy(this, "step"), - }; - this.steps = []; - } - - async step(t: Deno.TestStepDefinition): Promise; - async step( - name: string, - fn: (t: Deno.TestContext) => void | Promise, - ): Promise; - async step( - fn: (t: Deno.TestContext) => void | Promise, - ): Promise; - async step( - tOrNameOrFn: - | Deno.TestStepDefinition - | string - | ((t: Deno.TestContext) => void | Promise), - fn?: (t: Deno.TestContext) => void | Promise, - ): Promise { - let ignore = false; - if (typeof tOrNameOrFn === "function") { - ignore = false; - fn = tOrNameOrFn; - } else if (typeof tOrNameOrFn === "object") { - ignore = tOrNameOrFn.ignore ?? false; - fn = tOrNameOrFn.fn; - } - - const name = typeof tOrNameOrFn === "string" - ? tOrNameOrFn - : tOrNameOrFn.name; - const context = new TestContext(name); - this.steps.push(context); - if (!ignore) { - await fn!(context); - } - return !ignore; - } -} +import { TestContext } from "./_test_helpers.ts"; const baseStepOptions: Omit = { ignore: false,