-
-
Notifications
You must be signed in to change notification settings - Fork 247
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
Has test helper and scoping into first result #226
Comments
Hi, Although your assertions are all passing, the reason the test itself is still failing is because of the built-in interaction check. This check automatically occurs in every The recommended way to solve this, is to interact with all fields in that scope using the $response
->assertStatus(200)
->assertInertia(fn (InertiaAssert $page) => $page
->has('users.data', 1, fn (InertiaAssert $page) => $page
->where('email', 'thisusersemail@example.com')
->hasAll([
'id',
'username',
'first_name',
'surname',
'email_verified_at',
'blocked',
'created_at',
'updated_at'
])
)
); Alternatively, if you simply don't care about this automatic behaviour, you can chain $response
->assertStatus(200)
->assertInertia(fn (InertiaAssert $page) => $page
->has('users.data', 1, fn (InertiaAssert $page) => $page
->where('email', 'thisusersemail@example.com')
->missing('password')
->etc()
)
); In case the above still doesn't make sense, I've written a more in-depth explanation of it here: Hope this helps! |
Thank you for the detailed response and also the additional link. That makes sense now and I've got my tests passing using either of your suggested methods. Great to see this integrated into the Inertia Laravel adapter now and also the Laravel framework. Thanks again. |
Hi, I'm trying to use the
has
andwhere
test helpers and I can't understand why the following test is failing.users.data
is returned from Laravel's paginate method and I'm trying to assert that there is 1 result and then scope into that result and assert that the email of that user isthisusersemail@example.com
.I then get the following test failure which lists the other properties on the users model but without the email property.
I've dumped the $page variable and it does include the correct email address. I'm not sure if this is a bug or I'm using the helpers incorrectly.
For reference I can make the test pass using the following assertions but I'd like to combine the count and then scope straight into the first result as mentioned in the documentation.
Thanks for your help.
The text was updated successfully, but these errors were encountered: