我的刀片中有以下内容...
<div>
<contact-form></contact-form>
</div>
我想测试以确保 Vue.js 组件始终安装在我的测试中......
public function testRoute()
{
$this->visit('/');
//stuck here
}
基本上,我期待着测试刀片是否具有<contact-form>. 我应该如何进行?
采用assertSee
断言给定的字符串包含在响应中
$this
->visit('/')
->assertSee('<contact-form>')
->assertSee('</contact-form>');
在此处查看更多 laravel 5.5 测试断言
或者,如果您想深入了解客户端浏览器测试,请查看Laravel Dusk,它有assertSourceHas方法。
您可以使用 trait 中的callorget方法MakesHttpRequests.php来检查文本:
// this returns \Illuminate\Foundation\Testing\TestResponse
$response = $this->get('/');
// use the TestResponse api
$response->assertSee($value);
Github 源码参考: https ://github.com/laravel/framework/blob/5.5/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php
https://github.com/laravel/framework/blob/5.5/src/Illuminate/Foundation/Testing/TestResponse.php