Laravel TDD assertSee returns true on NULL object
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 ?
Solution 1:
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