From ec7096495c756fd9a76b836f915bfee7a0725ee8 Mon Sep 17 00:00:00 2001 From: Koen Punt Date: Wed, 15 Dec 2021 14:42:43 +0100 Subject: [PATCH] Update testing reference documentation This commit updates the testing documentation after changes done with the 1.0.0-M4 release. Closes gh-224 --- .../src/docs/asciidoc/testing.adoc | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/spring-graphql-docs/src/docs/asciidoc/testing.adoc b/spring-graphql-docs/src/docs/asciidoc/testing.adoc index 0b3df81f..a946b173 100644 --- a/spring-graphql-docs/src/docs/asciidoc/testing.adoc +++ b/spring-graphql-docs/src/docs/asciidoc/testing.adoc @@ -205,8 +205,9 @@ The "JS GraphQL" plugin for IntelliJ supports GraphQL query files with code comp [[testing-errors]] == Errors -Tests cannot use verify data, if there are errors under the "errors" key in the response -has errors. If necessary to ignore an error, use an error filter `Predicate`: +Verify won't succeed when there are errors under the "errors" key in the response. + +If necessary to ignore an error, use an error filter `Predicate`: [source,java,indent=0,subs="verbatim,quotes"] ---- @@ -229,6 +230,22 @@ An error filter can be registered globally and apply to all tests: .build(); ---- + +Or to expect an error, and in contrast to `filter`, throw an assertion error +when it doesn't exist in the response: + +[source,java,indent=0,subs="verbatim,quotes"] +---- + graphQlTester.query(query) + .execute() + .errors() + .expect(error -> ...) + .verify() + .path("project.releases[*].version") + .entityList(String.class) + .hasSizeGreaterThan(1); +---- + Or inspect all errors directly and that also marks them as filtered: [source,java,indent=0,subs="verbatim,quotes"]