Change record status: 
Project: 
Introduced in branch: 
10.3.x
Introduced in version: 
10.3.0
Description: 

JSON:API tests that expect a response document with data now verify the existence on the data attribute and give usefull errors when they fail.

Use this in tests by using the getDocumentFromResponse method in the Drupal\Tests\jsonapi\Traits\GetDocumentFromRequestTrait. The getDocumentFromResponse accepts 2 arguments. The response (Psr\Http\Message\ResponseInterface) and a second argument $validate. If the test does not need a data attribute, because it tests failure codes or errors, set $validate to FALSE, no validation will then happen in regards to the expected data attribute.

Example of how things changed:

Old error:

1) Drupal\Tests\jsonapi\Functional\JsonApiFunctionalTest::testWrite
Undefined array key "data"

New Error:

1) Drupal\Tests\jsonapi\Functional\JsonApiFunctionalTest::testWrite
    Missing expected data property in document. Error(s): 
      Bad Request (400): Resource object must include a "type".
Impacts: 
Module developers
Site templates, recipes and distribution developers