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

Function assertOptions

testing/bdd_test.ts:149–184  ·  view source on GitHub ↗

* Asserts that `Deno.test` is called with the correct options for the `it` call in the callback function. * This is used to reduce code duplication when testing calling `it` with different call signatures.

(
    expectedOptions: Omit<Deno.TestDefinition, "name" | "fn">,
    cb: (fn: Spy) => void,
  )

Source from the content-addressed store, hash-verified

147 * This is used to reduce code duplication when testing calling `it` with different call signatures.
148 */
149 async function assertOptions<T>(
150 expectedOptions: Omit<Deno.TestDefinition, "name" | "fn">,
151 cb: (fn: Spy) => void,
152 ) {
153 using test = stub(Deno, "test");
154 const fn = spy();
155 try {
156 cb(fn);
157
158 assertSpyCalls(fn, 0);
159 assertSpyCall(test, 0);
160 const call = test.calls[0];
161 const options = call?.args[0] as Deno.TestDefinition;
162 assertEquals(
163 Object.keys(options).sort(),
164 ["name", "fn", ...Object.keys(expectedOptions)].sort(),
165 );
166 assertObjectMatch(options, {
167 name: "example",
168 ...expectedOptions,
169 });
170
171 const context = new TestContext("example");
172 const result = options.fn(context);
173 assertStrictEquals(Promise.resolve(result), result);
174 assertEquals(await result, undefined);
175 assertSpyCalls(context.spies.step, 0);
176 assertSpyCall(fn, 0, {
177 self: {},
178 args: [context],
179 returned: undefined,
180 });
181 } finally {
182 TestSuiteInternal.reset();
183 }
184 }
185
186 /**
187 * Asserts that `Deno.test` is called with just the name and function for the `it` call in the callback function.

Callers 2

assertMinimumOptionsFunction · 0.85
assertAllOptionsFunction · 0.85

Calls 9

stubFunction · 0.90
spyFunction · 0.90
assertSpyCallsFunction · 0.90
assertSpyCallFunction · 0.90
assertEqualsFunction · 0.90
assertObjectMatchFunction · 0.90
assertStrictEqualsFunction · 0.90
keysMethod · 0.80
resetMethod · 0.45

Tested by

no test coverage detected