I'm using Laravel 5.1 Testsuite.
Now, I test my json api with the method seeJson(). This method expects an array, such as:
->seeJson(['created' => 1]);
But my json api always returns a json object or an array with json objects with, in this case:
Response::json(['created' => 1], 200);
In the case above, my json api returns:
{created: 1}
But seeJson() looks for the given array exactly:
[created: 1]
I never get my tests pass with a match. How can I match?
I received a similar error.
Unable to find JSON fragment ["created":1] within [{"created":"1"}......]
Looking at the source code, that error is written as:
"Unable to find JSON fragment [{$expected}] within [{$actual}]."
So the [
]
are not being included in the search
Response::json(['created' => 1], 200);
results in:
{"created":1}
When I dump out the response content within the seeJson()
method, all values are in quotes. Try changing your test to:
->seeJson(['created' => '1']);
seeJson
make strict comparisons, so:
'created' => 1 (Interpreted as integer)
Will fail because the JSON returned by your API is actually
"created":"1" (interpreted as string)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With