Skip to content

Jest Testing Resolvers with Typedi #1379

Answered by kicks321
kicks321 asked this question in Q&A
Discussion options

You must be logged in to vote

Actually, I figured it out.

So there's two sets of test you have going on. Unit / Integration.

For Unit testing, you want to test the raw "non-containerized" approach. Bascially just raw ES6. You create a mock version of your service class and just pass it as an instance directly to the constructor.

// Mocks
jest.spyOn(MockService.prototype, 'myFunction').mockReturnValue(() => Promise.resolve({ // Your mock object with Faker or something goes here }))

// Set-up
const mockService = new MockService();
const resolver = new Resolver(mockService);

// Then run your test like so
await resolver.runSomething() ==> this function basically calls your mocked function from the mock Service

For Inte…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kicks321
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant