Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/unitest/matcher/to_have_property.ts>toHaveProperty

🃏 Deno-first universal unit testing framework
Latest
function toHaveProperty
import { toHaveProperty } from "https://deno.land/x/unitest@v1.0.0-beta.82/matcher/to_have_property.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