Skip to main content
Module

x/unitest/mod.ts>toHaveProperty

🃏 Deno-first universal unit testing framework
Latest
function toHaveProperty
Re-export
import { toHaveProperty } from "https://deno.land/x/unitest@v1.0.0-beta.82/mod.ts";

Use .toHaveProperty to check if property at provided reference keyPath exists for an object

import { expect, test } from "https://deno.land/x/unitest@$VERSION/mod.ts";

test("passes when check object property via keyPath", () => {
  expect({ a: "b" }).toHaveProperty("a");
  expect({ a: { b: { c: "d" } } }).toHaveProperty("a.b.c");
  expect({ a: { b: { c: "d" } } }).not.toHaveProperty(["a", "b", "c"], "e");
});

Parameters

actual: object
keyPath: PropertyKey | PropertyKey[]
optional
value: unknown