MCPcopy Create free account
hub / github.com/denoland/std / describeDefinition

Function describeDefinition

testing/bdd.ts:1082–1147  ·  view source on GitHub ↗

Generates a DescribeDefinition from DescribeArgs.

(
  ...args: DescribeArgs<T>
)

Source from the content-addressed store, hash-verified

1080
1081/** Generates a DescribeDefinition from DescribeArgs. */
1082function describeDefinition<T>(
1083 ...args: DescribeArgs<T>
1084): DescribeDefinition<T> {
1085 let [
1086 suiteOptionsOrNameOrFn,
1087 optionsOrNameOrFn,
1088 optionsOrFn,
1089 fn,
1090 ] = args;
1091 let suite: TestSuite<T> | undefined = undefined;
1092 let name: string;
1093 let options:
1094 | DescribeDefinition<T>
1095 | Omit<DescribeDefinition<T>, "fn">
1096 | Omit<DescribeDefinition<T>, "name">
1097 | Omit<DescribeDefinition<T>, "fn" | "name">;
1098 if (
1099 typeof suiteOptionsOrNameOrFn === "object" &&
1100 typeof (suiteOptionsOrNameOrFn as TestSuite<T>).symbol === "symbol"
1101 ) {
1102 suite = suiteOptionsOrNameOrFn as TestSuite<T>;
1103 } else {
1104 fn = optionsOrFn as typeof fn;
1105 optionsOrFn = optionsOrNameOrFn as typeof optionsOrFn;
1106 optionsOrNameOrFn = suiteOptionsOrNameOrFn as typeof optionsOrNameOrFn;
1107 }
1108 if (typeof optionsOrNameOrFn === "string") {
1109 name = optionsOrNameOrFn;
1110 if (typeof optionsOrFn === "function") {
1111 fn = optionsOrFn;
1112 options = {};
1113 } else {
1114 options = optionsOrFn ?? {};
1115 if (fn === undefined) {
1116 fn = (options as Omit<DescribeDefinition<T>, "name">).fn;
1117 }
1118 }
1119 } else if (typeof optionsOrNameOrFn === "function") {
1120 fn = optionsOrNameOrFn;
1121 name = fn.name;
1122 options = {};
1123 } else {
1124 options = optionsOrNameOrFn ?? {};
1125 if (typeof optionsOrFn === "function") {
1126 fn = optionsOrFn;
1127 } else {
1128 fn = (options as DescribeDefinition<T>).fn;
1129 }
1130 name = (options as DescribeDefinition<T>).name ?? fn?.name ?? "";
1131 }
1132
1133 if (suite === undefined) {
1134 suite = options.suite;
1135 }
1136 if (suite === undefined && TestSuiteInternal.current) {
1137 const { symbol } = TestSuiteInternal.current;
1138 suite = { symbol };
1139 }

Callers 2

describeFunction · 0.85
bdd.tsFile · 0.85

Calls

no outgoing calls

Tested by 1

describeFunction · 0.68