summaryrefslogtreecommitdiff
path: root/cli/tests/unit/testing_test.ts
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2021-11-23 14:57:51 +0100
committerGitHub <noreply@github.com>2021-11-23 14:57:51 +0100
commitd8afd5683857de83f3cc80c33322df3d65377210 (patch)
tree0ffb7f1e94994282aadc6f6c342a1884c19774ae /cli/tests/unit/testing_test.ts
parentae34f8fa10f4daddde3d32cc63773d288253d4d4 (diff)
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>): void; // Deno.test("test name", { only: true }, function() { }); export function test( name: string, options: Omit<TestDefinition, "name">, fn: (t: TestContext) => void | Promise<void>, ): void; // Deno.test({ name: "test name" }, function() { }); export function test( options: Omit<TestDefinition, "fn">, fn: (t: TestContext) => void | Promise<void>, ): void; // Deno.test({ only: true }, function testName() { }); export function test( options: Omit<TestDefinition, "fn" | "name">, fn: (t: TestContext) => void | Promise<void>, ): void; ```
Diffstat (limited to 'cli/tests/unit/testing_test.ts')
-rw-r--r--cli/tests/unit/testing_test.ts60
1 files changed, 57 insertions, 3 deletions
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() {