Replies: 1 comment 3 replies
-
…
But if this is the field we're talking about, it's even nullable on multiple places:
As for your specific case, it would much easier to debug if you can produce a self-contained example. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am having difficulties writing tests for something that throws an exception.
To simplify, I have a Type something like this:
Now when I test this field resolver in GraphQL graphical interface or send a request to GraphQL end point which has that field resolving, I get an exception, the stacktrace and so on. Working as intended.
However in my feature tests, this exception gets swallowed and the field resolves to a
null
value, no exception is thrown.Through my research I found that exceptions get handled differently depending on what they are and if they are nullable. To my knowledge, my field is not nullable. https://webonyx.github.io/graphql-php/error-handling/
And I see this Exception being handled in here, so it definitely has bubbled up https://github.com/rebing/graphql-laravel/blob/master/src/GraphQL.php#L532-L562
Laravel helper test method
$this->withoutExceptionHandling();
in my test does nothing and the field resolves tonull
regardless.It is only when I expect an exception through something like
$this->expectException(AssetNotFoundException::class);
in my test that I start to see the exception in the console.Cool! But.. it says:
It says there was no exception thrown with my expected exception, but then proceeds to say otherwise. I find it a bit weird that it says the error happened in "last request".
For reference, this is roughly how my test looks:
What am I doing wrong? Is there perhaps a bug in how this package handles exceptions? Have I misunderstood testing conceptually? How do I correctly assert exception being thrown?
Please advise. Thank you!
Beta Was this translation helpful? Give feedback.
All reactions