From 403f93ec27708a98936340f06271b44320eec6b0 Mon Sep 17 00:00:00 2001 From: lts372005 <87189679+lts372005@users.noreply.github.com> Date: Sat, 30 Oct 2021 10:49:49 +0700 Subject: [PATCH] [Unit Test] utils: delay --- tests/local.ts | 4 ++-- tests/util/{hasProperty.ts => utils.ts} | 17 ++++++++++++++++- .../{validateLength.ts => validate_length.ts} | 0 3 files changed, 18 insertions(+), 3 deletions(-) rename tests/util/{hasProperty.ts => utils.ts} (51%) rename tests/util/{validateLength.ts => validate_length.ts} (100%) diff --git a/tests/local.ts b/tests/local.ts index 5858743f4..bba4ce566 100644 --- a/tests/local.ts +++ b/tests/local.ts @@ -1,4 +1,4 @@ import "./local/snowflake.ts"; -import "./util/validateLength.ts"; -import "./util/hasProperty.ts"; +import "./util/validate_length.ts"; +import "./util/utils.ts"; import "./util/hash.ts"; diff --git a/tests/util/hasProperty.ts b/tests/util/utils.ts similarity index 51% rename from tests/util/hasProperty.ts rename to tests/util/utils.ts index 7cf0bd412..8ec25bee2 100644 --- a/tests/util/hasProperty.ts +++ b/tests/util/utils.ts @@ -1,5 +1,8 @@ -import { hasProperty } from "../../src/util/utils.ts"; +import { hasProperty, delay } from "../../src/util/utils.ts"; import { assertEquals } from "../deps.ts"; + +// hasProperty + const obj = { prop: "lts372005" }; Deno.test({ name: "[utils] hasProperty does HAVE property", @@ -13,3 +16,15 @@ Deno.test({ assertEquals(hasProperty(obj, "lts372005"), false); }, }); + +// delay + +Deno.test({ + name: "[utils] delay 2000 ms", + async fn() { + const before = Date.now(); + await delay(2000); + const after = Date.now(); + if (after - before < 2000) throw new Error(`delay(2000) delayed ${after - before}ms`); + }, +}); diff --git a/tests/util/validateLength.ts b/tests/util/validate_length.ts similarity index 100% rename from tests/util/validateLength.ts rename to tests/util/validate_length.ts