Unit testing a method decorator created using createMethodDecorator #1410
-
I have a factory function that uses the createMethodDecorator method to create a decorator that looks like this:
and a test class inside of my jest .test.ts that uses it that looks like this:
The TestEntity is a simple class with a single field called "id". and then finally, a set of expectations and a call to it that looks like this:
My basic understanding of standard typescript decorators was that upon calling resolve, I would see the following order of log messages:
However, I only see the first and last messages. If I use a standard typescript decorator factory method like so:
I see the messages in the order I described. I need the authorizedUser from the IGraphQLContext, so I can't revert back to the standard decorator syntax. I know the decorator works because when I use it on an actual resolver within a service, I see the messages I expect. I don't know how why in the context of a test it isn't working, though. I've tried decorating the resolver and entity like one of our actual production resolvers and entities, but that also didn't work. I also tried a few different permutations of declaring the decorator as a variable and trying to call it myself, with no success. I went looking through the docs and found several examples of how to use the createMethodDecorator method, but came up short finding unit test code to exercise them. Hoping I'm missing something simple. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
TypeGraphQL decorators works inside GraphQL runtime. When you call that resolver methods, it's executed outside the pipeline. So you can't expect |
Beta Was this translation helpful? Give feedback.
TypeGraphQL decorators works inside GraphQL runtime. When you call that resolver methods, it's executed outside the pipeline. So you can't expect
next
to work as it's a framework initialized function to control execution of middlewares and resolvers.