Reputation: 3947
Whenever I try to test some object property which does not exists (which is actually null), tests passes when using $this->assertSee($record->someNonExistingProperty)
:
public function test_a_user_should_be_able_to_see_a_consumer_address()
{
$this->get(route('users.index'))->assertSee($this->user->address);
}
$this->user->address
does not exists, but test returns green
What's wrong with that assertion ?
Upvotes: 0
Views: 860
Reputation: 3162
A workaround for this is to use a null coalescing operator like:
$response ->assertSeeText($this->user->address ?? '**No Address Field**')
This part $this->user->address ?? '**No Address Field**'
checks if there is a $this->user->address
and if not returns **No Address Field**
- as long as your view does not show this text it will fail.
So basically change the text of **No Address Field**
to something you want to see in the test results to identify the missing key, but is not present in the view.
Upvotes: 0
Reputation: 4032
My guess would be this, it is asserting it can see nothing/everything.
If $this->user->address
return null
then your assertion would equate to this:
$this->get(route('users.index'))->assertSee(null);
I would also do an assertion on your objects property too. Like so:
$this->assertTrue($this->user->address !== null);
$this->get(route('users.index'))->assertSee($this->user->address);
The documentation on assert see states it looks for a string and will escape any value it is given
https://laravel.com/docs/7.x/http-tests#assert-see
Upvotes: 1