Skip to content

test: add tests for Readme component#1953

Merged
asyncapi-bot merged 4 commits intoasyncapi:masterfrom
batchu5:test/add-tests-readme-component
Feb 12, 2026
Merged

test: add tests for Readme component#1953
asyncapi-bot merged 4 commits intoasyncapi:masterfrom
batchu5:test/add-tests-readme-component

Conversation

@batchu5
Copy link
Contributor

@batchu5 batchu5 commented Feb 8, 2026

Adds comprehensive tests for the Readme component to verify correct rendering and error behavior.

What’s included :

  • Snapshot test for rendering Readme with all required parameters\
  • Snapshot tests covering rendering

Fixes #1940

Summary by CodeRabbit

  • Tests
    • Added a new test suite for the Readme component.
    • Verifies rendering and snapshot stability across JavaScript and Python configurations.
    • Uses an AsyncAPI fixture to validate rendered output across languages.
    • No public API or exported signatures were changed.

@changeset-bot
Copy link

changeset-bot bot commented Feb 8, 2026

⚠️ No Changeset found

Latest commit: 2b22b3c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@asyncapi-bot
Copy link
Contributor

What reviewer looks at during PR review

The following are ideal points maintainers look for during review. Reviewing these points yourself beforehand can help streamline the review process and reduce time to merge.

  1. PR Title: Use a concise title that follows our Conventional Commits guidelines and clearly summarizes the change using imperative mood (it means spoken or written as if giving a command or instruction, like "add new helper for listing operations")

    Note - In Generator, prepend feat: or fix: in PR title only when PATCH/MINOR release must be triggered.

  2. PR Description: Clearly explain the issue being solved, summarize the changes made, and mention the related issue.

    Note - In Generator, we use Maintainers Work board to track progress. Ensure the PR Description includes Resolves #<issue-number> or Fixes #<issue-number> this will automatically close the linked issue when the PR is merged and helps automate the maintainers workflow.

  3. Documentation: Update the relevant Generator documentation to accurately reflect the changes introduced in the PR, ensuring users and contributors have up-to-date guidance.

  4. Comments and JSDoc: Write clear and consistent JSDoc comments for functions, including parameter types, return values, and error conditions, so others can easily understand and use the code.

  5. DRY Code: Ensure the code follows the Don't Repeat Yourself principle. Look out for duplicate logic that can be reused.

  6. Test Coverage: Ensure the new code is well-tested with meaningful test cases that pass consistently and cover all relevant edge cases.

  7. Commit History: Contributors should avoid force-pushing as much as possible. It makes it harder to track incremental changes and review the latest updates.

  8. Template Design Principles Alignment: While reviewing template-related changes in the packages/ directory, ensure they align with the Assumptions and Principles. If any principle feels outdated or no longer applicable, start a discussion these principles are meant to evolve with the project.

  9. Reduce Scope When Needed: If an issue or PR feels too large or complex, consider splitting it and creating follow-up issues. Smaller, focused PRs are easier to review and merge.

  10. Bot Comments: As reviewers, check that contributors have appropriately addressed comments or suggestions made by automated bots. If there are bot comments the reviewer disagrees with, react to them or mark them as resolved, so the review history remains clear and accurate.

@coderabbitai
Copy link

coderabbitai bot commented Feb 8, 2026

📝 Walkthrough

Walkthrough

Adds a new test suite Readme.test.js that parses an AsyncAPI fixture, renders the Readme component for two language configs (javascript, python), and performs snapshot assertions across those scenarios using a shared parsed document prepared in beforeAll.

Changes

Cohort / File(s) Summary
Readme Component Tests
packages/components/test/components/Readme.test.js
New test file: parses an AsyncAPI fixture in beforeAll, iterates over language configurations (javascript, python) with client file names, renders Readme with props, and performs snapshot assertions. Focus areas: fixture parsing, language/config iteration, and snapshot output.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title follows Conventional Commits format with 'test:' prefix and uses imperative mood to clearly describe adding tests for the Readme component.
Linked Issues check ✅ Passed The PR adds comprehensive unit tests for the Readme component including snapshot tests and prop validation error behavior, fulfilling issue #1940 requirements.
Out of Scope Changes check ✅ Passed All changes are scoped to adding tests for the Readme component as required by issue #1940; no unrelated code modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@packages/components/test/components/Readme.test.js`:
- Around line 14-25: The test reuses JS-specific params (params built via
buildParams('javascript', { clientFileName: 'myClient.js' }, 'production')) for
the Python snapshot, causing mismatched output; update the test to build
language-appropriate params inside the languages.forEach loop (or rebuild per
iteration) using buildParams(language, { clientFileName:
appropriateExtensionFor(language) }, 'production') so each iteration uses a
correct clientFileName/params for the current language variable rather than the
single params created in beforeAll.
- Around line 78-89: Add explicit validation in the Readme component to check
the incoming language prop against the supported languages set (the same source
used by Usage/usageConfig and CoreMethods) and throw a clear Error like
"Unsupported language: <language>" immediately if it's not supported; do this
before rendering child components (so Usage's lookup won't run on undefined).
Reference the Readme component's render/functional entry point and the supported
languages source (usageConfig / CoreMethods supported list) to perform the
check, and also ensure Installation.js receives a validated language or a safe
fallback so it doesn't render "undefined".
🧹 Nitpick comments (1)
packages/components/test/components/Readme.test.js (1)

42-141: Consider consolidating repetitive negative tests with test.each.

The seven error-case tests follow an identical pattern (render with bad props → expect TypeError). Using test.each would reduce duplication and make it easier to add new cases.

Example consolidation
-  test('render Readme component when asyncapi is missing', () => {
-    const renderReadme = () =>
-      render(
-        <Readme
-          params={params}
-          language="javascript"
-        />
-      );
-
-    expect(renderReadme).toThrow(TypeError);
-  });
-
-  test('render Readme component when params are missing', () => { ... });
-  // ... etc.
+  test.each([
+    ['asyncapi is missing',    { params, language: 'javascript' }],
+    ['params are missing',     { asyncapi: parsedAsyncAPIDocument, language: 'javascript' }],
+    ['language is missing',    { asyncapi: parsedAsyncAPIDocument, params }],
+    ['asyncapi is null',       { asyncapi: null, params, language: 'javascript' }],
+    ['params is null',         { asyncapi: parsedAsyncAPIDocument, params: null, language: 'javascript' }],
+    ['language is null',       { asyncapi: parsedAsyncAPIDocument, params, language: null }],
+    ['language is empty',      { asyncapi: parsedAsyncAPIDocument, params, language: '' }],
+    ['language is unsupported',{ asyncapi: parsedAsyncAPIDocument, params, language: 'dart' }],
+  ])('throws TypeError when %s', (_label, props) => {
+    expect(() => render(<Readme {...props} />)).toThrow(TypeError);
+  });

Note: Since parsedAsyncAPIDocument and params are set in beforeAll, you'd need to define the cases inside the describe block or use a factory function.

Comment on lines 78 to 89
test('render Readme with unsupported language', () => {
const renderReadme = () =>
render(
<Readme
asyncapi={parsedAsyncAPIDocument}
params={params}
language='dart'
/>
);

expect(renderReadme).toThrow(TypeError);
});
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find component files
echo "=== Searching for Installation component ==="
fd -i installation . --type f | head -20

echo -e "\n=== Searching for Usage component ==="
fd -i usage . --type f | head -20

echo -e "\n=== Searching for CoreMethods component ==="
fd -i coremethods . --type f | head -20

echo -e "\n=== Searching for Readme component ==="
fd -i readme . --type f | head -20

Repository: asyncapi/generator

Length of output: 1543


🏁 Script executed:

#!/bin/bash
# Check the Readme component first
echo "=== Readme.js component ==="
cat ./packages/components/src/components/readme/Readme.js

echo -e "\n=== Installation.js component ==="
cat ./packages/components/src/components/readme/Installation.js

echo -e "\n=== Usage.js component ==="
cat ./packages/components/src/components/readme/Usage.js

echo -e "\n=== CoreMethods.js component ==="
cat ./packages/components/src/components/readme/CoreMethods.js

Repository: asyncapi/generator

Length of output: 7612


🏁 Script executed:

#!/bin/bash
# Verify the test file to understand the full context
cat -n ./packages/components/test/components/Readme.test.js | sed -n '70,95p'

Repository: asyncapi/generator

Length of output: 826


🏁 Script executed:

#!/bin/bash
# Check if there's an empty string language test mentioned in the review
cat -n ./packages/components/test/components/Readme.test.js | grep -A 10 "empty string"

Repository: asyncapi/generator

Length of output: 418


🏁 Script executed:

#!/bin/bash
# Check the complete test file to understand the context of all language tests
wc -l ./packages/components/test/components/Readme.test.js
echo ""
cat -n ./packages/components/test/components/Readme.test.js | head -150

Repository: asyncapi/generator

Length of output: 4525


Add explicit language validation to the Readme component instead of relying on child component errors.

The TypeError is thrown, but not by explicit validation—it's an accidental side effect of Usage.js trying to call usageConfig[language] as a function when it's undefined. The CoreMethods.js component explicitly validates and throws a proper Error for unsupported languages, but it's never reached because Usage fails first. Additionally, Installation.js silently renders "undefined" without any validation. This creates fragile, implicit error handling that depends on component render order. Add explicit language validation with a clear error message at the Readme level before passing to child components.

🤖 Prompt for AI Agents
In `@packages/components/test/components/Readme.test.js` around lines 78 - 89, Add
explicit validation in the Readme component to check the incoming language prop
against the supported languages set (the same source used by Usage/usageConfig
and CoreMethods) and throw a clear Error like "Unsupported language: <language>"
immediately if it's not supported; do this before rendering child components (so
Usage's lookup won't run on undefined). Reference the Readme component's
render/functional entry point and the supported languages source (usageConfig /
CoreMethods supported list) to perform the check, and also ensure
Installation.js receives a validated language or a safe fallback so it doesn't
render "undefined".

@Adi-204 Adi-204 self-assigned this Feb 9, 2026
@Adi-204 Adi-204 moved this to In Progress in Maintainers work Feb 9, 2026
Comment on lines 26 to 30
const params = buildParams(
language,
{ clientFileName },
'production'
);
Copy link
Member

Choose a reason for hiding this comment

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

I would not recommend using this helper buildParams. As in actual code of Readme we don't use this helper. Additionally if the helper changes all other test will start failing and this helper has nothing to do with Readme component. Just use directly object.

Comment on lines 44 to 55
test.each([
['asyncapi is missing', { params, language: 'javascript' }],
['params are missing', { asyncapi: parsedAsyncAPIDocument, language: 'javascript' }],
['language is missing', { asyncapi: parsedAsyncAPIDocument, params }],
['asyncapi is null', { asyncapi: null, params, language: 'javascript' }],
['params is null', { asyncapi: parsedAsyncAPIDocument, params: null, language: 'javascript' }],
['language is null', { asyncapi: parsedAsyncAPIDocument, params, language: null }],
['language is empty', { asyncapi: parsedAsyncAPIDocument, params, language: '' }],
['language is unsupported',{ asyncapi: parsedAsyncAPIDocument, params, language: 'dart' }],
])('throws TypeError when %s', (_label, props) => {
expect(() => render(<Readme {...props} />)).toThrow(TypeError);
});
Copy link
Member

Choose a reason for hiding this comment

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

remove this testcase for now no need!

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@packages/components/test/components/Readme.test.js`:
- Around line 9-42: Add the missing negative test that asserts Readme throws
when a required prop is omitted: create a new test named like "throws when
required asyncapi prop is missing" that calls render with Readme but without the
asyncapi prop (provide minimal params and language) and assert that the call
throws using expect(...).toThrow(); reference the Readme component and the
render helper to locate where to add the test alongside the existing
languageConfigs tests.
🧹 Nitpick comments (1)
packages/components/test/components/Readme.test.js (1)

17-20: No guard if the fixture fails to parse.

If parseResult.document is null (e.g., fixture has validation errors), all tests will fail with an obscure error. A quick assertion in beforeAll makes failures obvious:

     const parseResult = await fromFile(parser, asyncapi_websocket_query).parse();
     parsedAsyncAPIDocument = parseResult.document;
+    expect(parsedAsyncAPIDocument).toBeDefined();

@batchu5
Copy link
Contributor Author

batchu5 commented Feb 12, 2026

I had included similar nitpick comments in PR #1967, but Adi recommended removing them. Following the same approach, I think we can skip them here too.

@sonarqubecloud
Copy link

@Adi-204
Copy link
Member

Adi-204 commented Feb 12, 2026

@batchu5 always don't directly follow coderabbit suggestion, if you feel doubt just drop your comment (don't mark it resolve directly) why it is not need maintainer will verify and let you know.

@Adi-204
Copy link
Member

Adi-204 commented Feb 12, 2026

/rtm

@asyncapi-bot asyncapi-bot merged commit 6e8f60e into asyncapi:master Feb 12, 2026
14 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Maintainers work Feb 12, 2026
@batchu5
Copy link
Contributor Author

batchu5 commented Feb 12, 2026

I’m sorry, @Adi-204, that was my mistake. I won’t repeat it next time.

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

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Add Tests for Readme Component.

3 participants