From d8afd5683857de83f3cc80c33322df3d65377210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 23 Nov 2021 14:57:51 +0100 Subject: feat(test): Add more overloads for "Deno.test" (#12749) This commit adds 4 more overloads to "Deno.test()" API. ``` // Deno.test(function testName() { }); export function test(fn: (t: TestContext) => void | Promise): void; // Deno.test("test name", { only: true }, function() { }); export function test( name: string, options: Omit, fn: (t: TestContext) => void | Promise, ): void; // Deno.test({ name: "test name" }, function() { }); export function test( options: Omit, fn: (t: TestContext) => void | Promise, ): void; // Deno.test({ only: true }, function testName() { }); export function test( options: Omit, fn: (t: TestContext) => void | Promise, ): void; ``` --- cli/tests/unit/testing_test.ts | 60 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) (limited to 'cli/tests/unit') diff --git a/cli/tests/unit/testing_test.ts b/cli/tests/unit/testing_test.ts index 144246002..d4d25d12f 100644 --- a/cli/tests/unit/testing_test.ts +++ b/cli/tests/unit/testing_test.ts @@ -1,9 +1,63 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { assertRejects, assertThrows, unitTest } from "./test_util.ts"; -unitTest(function testFnOverloading() { - // just verifying that you can use this test definition syntax - Deno.test("test fn overloading", () => {}); +unitTest(function testWrongOverloads() { + assertThrows( + () => { + // @ts-ignore Testing invalid overloads + Deno.test("some name", { fn: () => {} }, () => {}); + }, + TypeError, + "Unexpected 'fn' field in options, test function is already provided as the third argument.", + ); + assertThrows( + () => { + // @ts-ignore Testing invalid overloads + Deno.test("some name", { name: "some name2" }, () => {}); + }, + TypeError, + "Unexpected 'name' field in options, test name is already provided as the first argument.", + ); + assertThrows( + () => { + // @ts-ignore Testing invalid overloads + Deno.test(() => {}); + }, + TypeError, + "The test function must have a name", + ); + assertThrows( + () => { + // @ts-ignore Testing invalid overloads + Deno.test(function foo() {}, {}); + }, + TypeError, + "Unexpected second argument to Deno.test()", + ); + assertThrows( + () => { + // @ts-ignore Testing invalid overloads + Deno.test({ fn: () => {} }, function foo() {}); + }, + TypeError, + "Unexpected 'fn' field in options, test function is already provided as the second argument.", + ); + assertThrows( + () => { + // @ts-ignore Testing invalid overloads + Deno.test({}); + }, + TypeError, + "Expected 'fn' field in the first argument to be a test function.", + ); + assertThrows( + () => { + // @ts-ignore Testing invalid overloads + Deno.test({ fn: "boo!" }); + }, + TypeError, + "Expected 'fn' field in the first argument to be a test function.", + ); }); unitTest(function nameOfTestCaseCantBeEmpty() { -- cgit v1.2.3