* 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,
)
| 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. |
no test coverage detected