From 0df18542499d1220f1182496d3b7028eef243eb0 Mon Sep 17 00:00:00 2001 From: Yongwook Choi Date: Wed, 6 Apr 2022 23:51:38 +0900 Subject: feat(test): Add "name", "origin" and "parent" to "Deno.TestContext" (#14007) This commit adds following fields to "Deno.TestContext" interface: - name - origin - parent These are prerequisites for supporting snapshot functionality in "std/testing". --- cli/tests/unit/testing_test.ts | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'cli/tests/unit') diff --git a/cli/tests/unit/testing_test.ts b/cli/tests/unit/testing_test.ts index 87b862a7d..90575aeb2 100644 --- a/cli/tests/unit/testing_test.ts +++ b/cli/tests/unit/testing_test.ts @@ -1,5 +1,5 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. -import { assertRejects, assertThrows } from "./test_util.ts"; +import { assertEquals, assertRejects, assertThrows } from "./test_util.ts"; Deno.test(function testWrongOverloads() { assertThrows( @@ -117,3 +117,33 @@ Deno.test(async function invalidStepArguments(t) { "Expected a test definition or name and function.", ); }); + +Deno.test(async function nameOnTextContext(t1) { + await assertEquals(t1.name, "nameOnTextContext"); + await t1.step("step", async (t2) => { + await assertEquals(t2.name, "step"); + await t2.step("nested step", async (t3) => { + await assertEquals(t3.name, "nested step"); + }); + }); +}); + +Deno.test(async function originOnTextContext(t1) { + await assertEquals(t1.origin, Deno.mainModule); + await t1.step("step", async (t2) => { + await assertEquals(t2.origin, Deno.mainModule); + await t2.step("nested step", async (t3) => { + await assertEquals(t3.origin, Deno.mainModule); + }); + }); +}); + +Deno.test(async function parentOnTextContext(t1) { + await assertEquals(t1.parent, undefined); + await t1.step("step", async (t2) => { + await assertEquals(t1, t2.parent); + await t2.step("nested step", async (t3) => { + await assertEquals(t2, t3.parent); + }); + }); +}); -- cgit v1.2.3