Fix vacuous-pass assertion in get.collection "wrong code" test - #7525
Fix vacuous-pass assertion in get.collection "wrong code" test#7525Nimra3261 wants to merge 1 commit into
Conversation
"wrong code returns an error" wrapped its assertions inside the catch
block: if collection.get() didn't throw, the catch body (and its
error.message check) never ran and the test passed vacuously instead
of failing.
Rewritten as await expect(...).rejects.toThrow(message), matching the
pattern already used elsewhere in this file ("should error on non
existing collection") and applied in chroma-core#7508/chroma-core#7509.
Addresses chroma-core#2801
Reviewer ChecklistPlease leverage this checklist to ensure your code review is thorough before approving Testing, Bugs, Errors, Logs, Documentation
System Compatibility
Quality
|
ErenAta16
left a comment
There was a problem hiding this comment.
Three more tests in this suite have the same shape, so the pattern outlives this PR.
| file | line | test |
|---|---|---|
add.collections.test.ts |
72 | It should return an error when inserting duplicate IDs in the same batch |
add.collections.test.ts |
84 | should error on empty embedding |
collection.config.client.test.ts |
614 | it should error if both schema and embedding function are provided |
All three are try { await ... } catch (e) { expect(...) } with nothing after the await inside the try, so if the call ever stops throwing the catch never runs and the test still reports green. Reduced to plain node:
const neverThrows = async () => "ok";
try { await neverThrows(); } catch (e) { /* assertions live here */ }
// -> falls through, test passes
await neverThrows().then(() => { throw new Error("resolved, expected rejection"); }, () => {});
// -> throws, test failscollection.config.client.test.ts:614 is the weakest of the three: the only assertion is expect(error).toBeDefined(), so even when it does throw it only checks that something was thrown.
add.collections.test.ts:62 — ten lines above the first one — already uses the idiom this PR switches to:
await expect(async () => {
await collection.add({ ids: IDS, embeddings: EMBEDDINGS });
}).rejects.toThrow();One difference worth deciding on rather than inheriting: toMatchInlineSnapshot was an exact match on the whole message, rejects.toThrow(string) is a substring match. Same message either way here, so nothing breaks — it just means a message that grows a suffix later won't be caught.
Read at 78e0d21.
"wrong code returns an error" wrapped its assertions inside the catch block:
If
collection.get()didn't throw, the catch body (and itserror.messagecheck) never ran and the test passed vacuously instead of failing.Rewritten as
await expect(...).rejects.toThrow(message), matching the pattern already used elsewhere in this file ("should error on non existing collection") and applied in #7508/#7509.Addresses #2801