* Asserts that when only is used on a nested `describe` or `it` call, it will be the only test case or suite that runs in the file. * This is used to reduce code duplication when testing calling `describe.ignore` with different call signatures.
(
cb: (fns: readonly [Spy, Spy, Spy]) => void,
)
| 1343 | * This is used to reduce code duplication when testing calling `describe.ignore` with different call signatures. |
| 1344 | */ |
| 1345 | async function assertOnly( |
| 1346 | cb: (fns: readonly [Spy, Spy, Spy]) => void, |
| 1347 | ) { |
| 1348 | using test = stub(Deno, "test"); |
| 1349 | const fns = [spy(), spy(), spy()] as const; |
| 1350 | try { |
| 1351 | cb(fns); |
| 1352 | |
| 1353 | assertSpyCall(test, 0); |
| 1354 | const call = test.calls[0]; |
| 1355 | const options = call?.args[0] as Deno.TestDefinition; |
| 1356 | assertEquals( |
| 1357 | Object.keys(options).sort(), |
| 1358 | ["name", "only", "fn"].sort(), |
| 1359 | ); |
| 1360 | assertObjectMatch(options, { |
| 1361 | name: "example", |
| 1362 | only: true, |
| 1363 | }); |
| 1364 | |
| 1365 | assertSpyCalls(fns[0], 0); |
| 1366 | assertSpyCalls(fns[1], 0); |
| 1367 | |
| 1368 | const context = new TestContext("example"); |
| 1369 | const result = options.fn(context); |
| 1370 | assertStrictEquals(Promise.resolve(result), result); |
| 1371 | assertEquals(await result, undefined); |
| 1372 | assertSpyCalls(context.spies.step, 1); |
| 1373 | |
| 1374 | let fn = fns[0]; |
| 1375 | assertSpyCalls(fn, 0); |
| 1376 | |
| 1377 | fn = fns[1]; |
| 1378 | assertSpyCall(fn, 0, { |
| 1379 | self: {}, |
| 1380 | returned: undefined, |
| 1381 | }); |
| 1382 | assertSpyCalls(fn, 1); |
| 1383 | |
| 1384 | fn = fns[2]; |
| 1385 | assertSpyCalls(fn, 0); |
| 1386 | } finally { |
| 1387 | TestSuiteInternal.reset(); |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | await t.step("it", async () => |
| 1392 | await assertOnly((fns) => { |
no test coverage detected