Skip to content
Open
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
12 changes: 1 addition & 11 deletions data_structures/binary_search_tree_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion testing/_test_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
54 changes: 1 addition & 53 deletions testing/bdd_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>;
async step(
name: string,
fn: (t: Deno.TestContext) => void | Promise<void>,
): Promise<boolean>;
async step(
fn: (t: Deno.TestContext) => void | Promise<void>,
): Promise<boolean>;
async step(
tOrNameOrFn:
| Deno.TestStepDefinition
| string
| ((t: Deno.TestContext) => void | Promise<void>),
fn?: (t: Deno.TestContext) => void | Promise<void>,
): Promise<boolean> {
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<Deno.TestStepDefinition, "name" | "fn"> = {
ignore: false,
Expand Down
Loading