Skip to content

Conversation

ashokbaruaakas
Copy link
Contributor

@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
Contributor 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
@pascalbaljet
Copy link
Member

I think this is a good idea! This would definitely help with testing, but I feel there’s a need for a more extensive way of testing props in general (like testing Lazy props in #595). So I'll keep this one open for a bit while considering a unified approach for this, as I don't want to end up with too many ways of testing props.

@pascalbaljet pascalbaljet merged commit cf9c8b3 into inertiajs:2.x Jun 5, 2025
18 checks passed
@pascalbaljet
Copy link
Member

Thanks!

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.

2 participants