UNPKG

1.09 kBJavaScriptView Raw
1import hasItems from '../utils/has-items.js';
2import { Predicate } from './predicate.js';
3export class WeakMapPredicate extends Predicate {
4 /**
5 @hidden
6 */
7 constructor(options) {
8 super('WeakMap', options);
9 }
10 /**
11 Test a WeakMap to include all the provided keys. The keys are tested by identity, not structure.
12
13 @param keys - The keys that should be a key in the WeakMap.
14 */
15 hasKeys(...keys) {
16 return this.addValidator({
17 message: (_, label, missingKeys) => `Expected ${label} to have keys \`${JSON.stringify(missingKeys)}\``,
18 validator: map => hasItems(map, keys),
19 });
20 }
21 /**
22 Test a WeakMap to include any of the provided keys. The keys are tested by identity, not structure.
23
24 @param keys - The keys that could be a key in the WeakMap.
25 */
26 hasAnyKeys(...keys) {
27 return this.addValidator({
28 message: (_, label) => `Expected ${label} to have any key of \`${JSON.stringify(keys)}\``,
29 validator: map => keys.some(key => map.has(key)),
30 });
31 }
32}