I am new in laravel 5.5 unit testing.
I wrote a method in NewsController names index. It returns a view like below:
public function index(Request $request)
{
$news = DB::table('news')->orderBy('created_at', 'desc')->get();
$data['news'] = $news;
return view('news.index')->with($data);
}
I wrote a test for that like below:
public function testIndex(){
factory(News::class, 10)->create();
$news = DB::table('news')->orderBy('created_at', 'desc')->get();
$this->get('/admin/news')
->assertViewHas('news', $news)
->assertStatus(200);
}
But test failed. The message is:
The response is not a view.
Can anyone help me?