Laravel TDD assertSee对NULL对象返回true

问题描述 投票:0回答:1

每当我试图测试一些不存在的对象属性(实际上是null)时,当我在使用 $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 不存在,但测试结果为绿色

这个断言有什么问题?

php laravel tdd
1个回答
1
投票

我的猜测是这样的,它是在断言它能看到什么都看不到。

如果 $this->user->address 返回 null 那么你的断言将等同于这样。

$this->get(route('users.index'))->assertSee(null);

我还会对你的对象属性做一个断言。像这样。

$this->assertTrue($this->user->address !== null);
$this->get(route('users.index'))->assertSee($this->user->address);

assert see的文档中写道: 它会寻找一个字符串,并且会转义任何给定的值。

https:/laravel.comdocs7.xhttp-tests#assert-see

© www.soinside.com 2019 - 2024. All rights reserved.