How can I write a test to return a json function in laravel
2 answers
You can take a look: https://laravel.com/docs/5.4/http-tests#testing-json-apis
Example (add this to your unit test file):
$this->json('post', 'your/route')
->assertStatus(200)
->assertJson([
'status' => 'OK',
]);
+1
source to share
You can use assertJson()
other similar methods in Laravel 5.4:
$this->json('put', 'api/some-url')
->assertStatus(200)
->assertJson([
'status' => 'OK',
'data' => [
'id' => 5,
]
]);
https://laravel.com/docs/5.4/http-tests#testing-json-apis
In Laravel 5.3 and below, JSON testing methods are different. Mostly used seeJson()
.
https://laravel.com/docs/5.3/application-testing#testing-json-apis
+1
source to share