deno.land / std@0.224.0 / collections / filter_keys_test.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "../assert/mod.ts";import { filterKeys } from "./filter_keys.ts";
function filterKeysTest<T>( input: [Record<string, T>, (key: string) => boolean], expected: Record<string, T>, message?: string,) { const actual = filterKeys(...input); assertEquals(actual, expected, message);}
Deno.test({ name: "filterKeys() handles no mutation", fn() { const object = { a: 5, b: true }; filterKeys(object, (key) => key !== "a");
assertEquals(object, { a: 5, b: true }); },});
Deno.test({ name: "filterKeys() handles empty input", fn() { filterKeysTest( [{}, () => true], {}, ); },});
Deno.test({ name: "filterKeys() handles identity", fn() { filterKeysTest( [ { foo: true, bar: "lorem", 1: -5, }, () => true, ], { foo: true, bar: "lorem", 1: -5, }, ); },});
Deno.test({ name: "filterKeys() handles filters", fn() { filterKeysTest( [ { foo: true, bar: "lorem", baz: 13, 1: -5, }, (it) => it.startsWith("b"), ], { bar: "lorem", baz: 13, }, ); filterKeysTest( [ { "Kim": 22, "Andrew": 14, "Marija": 34, }, (it) => it.length > 3, ], { "Andrew": 14, "Marija": 34, }, ); },});
Version Info