Skip to main content
Deno 2 is finally here ๐ŸŽ‰๏ธ
Learn more
Module

x/unitest/matcher/to_contain_keys.ts>toContainKeys

๐Ÿƒ Deno-first universal unit testing framework
Latest
function toContainKeys
import { toContainKeys } from "https://deno.land/x/unitest@v1.0.0-beta.82/matcher/to_contain_keys.ts";

Use .toContainKeys when checking if an object has all of the provided keys

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

const expect = defineExpect({
  matcherMap: {
    toContainKeys,
  },
  modifierMap: {
    not,
  },
});

test("passes when object contains all keys", () => {
  const object = { a: "foo", b: "bar", c: "baz" };
  expect(object).toContainKeys(["a", "b"]);
  expect(object).toContainKeys(["b", "c"]);
  expect(object).not.toContainKeys(["d"]);
});

Parameters

actual: object
expected: PropertyKey[]