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

[2.x] Introduce inertiaProps Method in TestResponseMacros for Improved Inertia.js Testing #700

Open
wants to merge 3 commits into
base: 2.x
Choose a base branch
from

Conversation

ashokbaruaakas
Copy link

@ashokbaruaakas ashokbaruaakas commented Dec 24, 2024

This commit introduces an enhanced inertiaProps method in the TestResponseMacros class, accompanied by comprehensive tests. The method streamlines the retrieval of specific properties from an Inertia.js response during testing. By leveraging Laravel's Arr::get utility, it supports accessing nested properties using dot notation and gracefully handles cases where the specified property is missing by returning a default value.

Feature

  • Direct Prop Extraction: Easily extract all props from the response.
  • Dot Notation Support: Access nested prop values using dot notation without causing exceptions.

Example usage:

$response->inertiaProps(); // Get All Props
$response->inertiaProps('user.name'); // Get Specific Props Value

This improvement enhances test readability and simplifies property assertions for developers working with Inertia.js.

Contribution of #659, #589

This commit introduces a new `inertiaProps` method in the `TestResponseMacros` class.
The method simplifies the process of retrieving specific props from an Inertia.js response
during testing. It uses Laravel's `Arr::get` utility to handle nested properties and
returns a default value if the specified prop is not found.

Example usage:
$response->inertiaProps('user.name');

This enhancement improves test readability and usability for Inertia.js developers.
@ashokbaruaakas ashokbaruaakas changed the title feat: add inertiaProps method for easier prop extraction in tests [2.x] add inertiaProps method for easier prop extraction in tests Dec 24, 2024
@ashokbaruaakas
Copy link
Author

Example use cases...

image

@ashokbaruaakas ashokbaruaakas changed the title [2.x] add inertiaProps method for easier prop extraction in tests [2.x] Enhance inertiaProps Method in TestResponseMacros for Improved Inertia.js Testing Dec 31, 2024
@ashokbaruaakas ashokbaruaakas changed the title [2.x] Enhance inertiaProps Method in TestResponseMacros for Improved Inertia.js Testing [2.x] Introduce inertiaProps Method in TestResponseMacros for Improved Inertia.js Testing Jan 3, 2025
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