Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement Proposal: Mocking Capabilities for Context-Specific Variables within Isolated Component Testing #10

Open
yihong1120 opened this issue Dec 28, 2023 · 1 comment

Comments

@yihong1120
Copy link

Dear Contributors,

I hope this message finds you well. I am writing to propose an enhancement to the astro-component-tester utility, which I have found to be an invaluable tool in the development of Astro components. The utility's ability to create an isolated testing environment is commendable; however, I have encountered a limitation that I believe could be addressed to further refine the testing experience.

Issue Description

The current implementation of astro-component-tester constructs an isolated environment for building components, which, while effective for most scenarios, does not account for context-specific variables such as Astro.request. This limitation becomes apparent when attempting to test components that rely on such context for their functionality. The absence of a mocking mechanism for these variables means that certain component behaviours cannot be accurately tested or replicated.

Proposed Solution

To enhance the utility's testing capabilities, I propose the introduction of a mocking framework that allows developers to simulate context-specific variables. This would enable a more comprehensive testing environment that can mimic the various states and conditions a component might encounter in a production setting.

Potential Implementation

A potential approach to this could involve:

  • Extending the getComponentOutput function to accept an additional parameter for context mocks.
  • Implementing a simple key-value mapping that the build process can utilise to replace context-specific variables with developer-provided mock data.
  • Providing documentation and examples on how to effectively use the mocking feature to simulate different scenarios.

Benefits

The inclusion of a mocking feature would provide several benefits:

  • It would allow for more thorough testing of components that depend on global context variables.
  • It would increase the confidence in the component's behaviour across different use cases.
  • It would align astro-component-tester with other testing frameworks that offer similar mocking capabilities, thereby enhancing its utility.

I am keen to hear your thoughts on this proposal and would be delighted to contribute to the implementation should there be consensus on its potential value.

Thank you for considering this enhancement. I look forward to a fruitful discussion.

Best regards,
yihong1120

@Princesseuh
Copy link
Owner

Hello!

Thank you for creating this issue, I agree that this would be very nice to add! Unfortunately, this project is very old and quite outdated for recent versions of Astro (It was created for Astro 0.23 originally, two years ago!), Astro is also working towards an official testing solution, the first step of which being the container API described here: withastro/roadmap#533

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

No branches or pull requests

2 participants