( collection: Collection<T>, predicate: (item: T) => boolean, message?: string, )
| 87 | * Assert that all items in a collection match a predicate |
| 88 | */ |
| 89 | export function assertAllItemsMatch<T extends object>( |
| 90 | collection: Collection<T>, |
| 91 | predicate: (item: T) => boolean, |
| 92 | message?: string, |
| 93 | ) { |
| 94 | const items = Array.from(collection.state.values()) |
| 95 | const failingItems = items.filter((item) => !predicate(item)) |
| 96 | |
| 97 | if (failingItems.length > 0) { |
| 98 | throw new Error( |
| 99 | message ?? |
| 100 | `${failingItems.length} item(s) did not match predicate: ${JSON.stringify(failingItems[0])}`, |
| 101 | ) |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Assert that items are sorted correctly |
no test coverage detected
searching dependent graphs…