Skip to content

[9.x] Add new TestResponse helper: assertJsonMissingPath#42361

Merged
taylorotwell merged 2 commits intolaravel:9.xfrom
danilopolani:feat/assert-json-missing-path
May 12, 2022
Merged

[9.x] Add new TestResponse helper: assertJsonMissingPath#42361
taylorotwell merged 2 commits intolaravel:9.xfrom
danilopolani:feat/assert-json-missing-path

Conversation

@danilopolani
Copy link
Contributor

This PR adds a new assertJsonMissingPath() HTTP Testing helper.
It's very useful to check that a path does dot exist, regardless of its content, especially for deep nested data.

$this->getJson('/users/1')
    ->assertOk()
    ->assertJsonMissingPath('email'); // Never return the user email

$this->getJson('/articles')
    ->assertOk()
    ->assertJsonMissingPath('data.0.internalTags');

Currently the only similar option is to use assertJsonMissing but you have to create the whole nested structure and know the data that should be inside and could be a pain sometimes, for example if wanting to check that an array does not exist and you don't know the order of its items.

@taylorotwell taylorotwell merged commit c894325 into laravel:9.x May 12, 2022
@danilopolani danilopolani deleted the feat/assert-json-missing-path branch May 12, 2022 15:26
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