UNPKG

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