1 | import hasItems from '../utils/has-items.js';
|
2 | import { Predicate } from './predicate.js';
|
3 | export class WeakSetPredicate extends Predicate {
|
4 | |
5 |
|
6 |
|
7 | constructor(options) {
|
8 | super('WeakSet', options);
|
9 | }
|
10 | |
11 |
|
12 |
|
13 |
|
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 | }
|