UNPKG

1.26 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.WeakMapPredicate = void 0;
4const has_items_1 = require("../utils/has-items");
5const predicate_1 = require("./predicate");
6class WeakMapPredicate extends predicate_1.Predicate {
7 /**
8 @hidden
9 */
10 constructor(options) {
11 super('WeakMap', options);
12 }
13 /**
14 Test a WeakMap to include all the provided keys. The keys are tested by identity, not structure.
15
16 @param keys - The keys that should be a key in the WeakMap.
17 */
18 hasKeys(...keys) {
19 return this.addValidator({
20 message: (_, label, missingKeys) => `Expected ${label} to have keys \`${JSON.stringify(missingKeys)}\``,
21 validator: map => has_items_1.default(map, keys)
22 });
23 }
24 /**
25 Test a WeakMap to include any of the provided keys. The keys are tested by identity, not structure.
26
27 @param keys - The keys that could be a key in the WeakMap.
28 */
29 hasAnyKeys(...keys) {
30 return this.addValidator({
31 message: (_, label) => `Expected ${label} to have any key of \`${JSON.stringify(keys)}\``,
32 validator: map => keys.some(key => map.has(key))
33 });
34 }
35}
36exports.WeakMapPredicate = WeakMapPredicate;