Skip to content

[TST] Improve Jest test assertions to use idiomatic matchers#6998

Open
atharva-deopujari wants to merge 1 commit intochroma-core:mainfrom
atharva-deopujari:chore/idiomatic-jest-tests
Open

[TST] Improve Jest test assertions to use idiomatic matchers#6998
atharva-deopujari wants to merge 1 commit intochroma-core:mainfrom
atharva-deopujari:chore/idiomatic-jest-tests

Conversation

@atharva-deopujari
Copy link
Copy Markdown

Description of changes

Improves the JavaScript client test suite to use idiomatic Jest matchers, as suggested in #2801. Two main patterns addressed:

expect(x.length).toBe(n)expect(x).toHaveLength(n) (13 instances)

  • Clearer failure messages showing the actual array contents instead of just the length number

try/catch with manual assertions → rejects.toThrow() (7 instances)

  • The old try/catch pattern would silently pass if the code didn't throw, since the expect inside catch would never execute. The rejects pattern correctly fails when the expected error is not thrown.

Changes are purely stylistic — no test logic was modified.

Test plan

  • Tests pass locally with pytest for python, yarn test for js, cargo test for rust

Documentation Changes

None

Relates to #2801

@github-actions
Copy link
Copy Markdown

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

@propel-code-bot
Copy link
Copy Markdown
Contributor

[TST] Standardize JS Jest Assertions with Idiomatic Matchers

This PR updates the JavaScript test suite to use more idiomatic Jest assertion patterns across 9 test files in clients/js/packages/chromadb-core/test/. The primary changes replace expect(x.length).toBe(n) with expect(x).toHaveLength(n) and convert manual async error try/catch assertion blocks into await expect(promise).rejects... assertions.

The changes are test-only and do not modify production logic. Besides stylistic consistency, the rejects conversions also tighten failure behavior by preventing false positives where tests could pass if no error was thrown.

This summary was automatically generated by @propel-code-bot

Copy link
Copy Markdown
Contributor

@propel-code-bot propel-code-bot Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review found no issues; test-only assertion refactors are consistent, clearer, and maintain intent.

Status: No Issues Found | Risk: Low

Review Details

📁 9 files reviewed | 💬 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant