Skip to content

Weird behaviour with type arguments when mocking Drizzle #85

Closed Answered by omermorad
fermentfan asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @fermentfan,

You are right about the error. The unitRef method returns the reference for the given dependency, but it is automatically mocked by Automock. Therefore, the returned type from unitRef.get(...) will always be a mocked instance, and it should be typed using the jest.Mocked generic type.

Here's the corrected code snippet:

import Mocked = jest.Mocked;

describe('LocationService', () => {
  let locationService: LocationService;
  let prismaService: Mocked<PrismaService>;
  let drizzleService: Mocked<DrizzleService>;

  beforeAll(() => {
    const { unit, unitRef } = TestBed.create(LocationService).compile();
    locationService = unit;

    drizzleService = unitRef.get(Drizz…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by omermorad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
2 participants
Converted from issue

This discussion was converted from issue #81 on August 02, 2023 07:19.