( collection: Collection<T>, expectedIds: Array<string>, message?: string, )
| 6 | * Assert that a collection has loaded exactly the expected items (no more, no less) |
| 7 | */ |
| 8 | export function assertLoadedExactly<T extends { id: string }>( |
| 9 | collection: Collection<T>, |
| 10 | expectedIds: Array<string>, |
| 11 | message?: string, |
| 12 | ) { |
| 13 | const loadedIds = getLoadedIds(collection) |
| 14 | const loadedSet = new Set(loadedIds) |
| 15 | const expectedSet = new Set(expectedIds) |
| 16 | |
| 17 | // Check for extra items |
| 18 | const extraIds = loadedIds.filter((id) => !expectedSet.has(id)) |
| 19 | if (extraIds.length > 0) { |
| 20 | throw new Error( |
| 21 | message ?? |
| 22 | `Collection has extra items: ${extraIds.join(`, `)} (expected only: ${expectedIds.join(`, `)})`, |
| 23 | ) |
| 24 | } |
| 25 | |
| 26 | // Check for missing items |
| 27 | const missingIds = expectedIds.filter((id) => !loadedSet.has(id)) |
| 28 | if (missingIds.length > 0) { |
| 29 | throw new Error( |
| 30 | message ?? |
| 31 | `Collection is missing items: ${missingIds.join(`, `)} (loaded: ${loadedIds.join(`, `)})`, |
| 32 | ) |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Assert that a collection has loaded at least the expected items (may have more) |
nothing calls this directly
no test coverage detected
searching dependent graphs…