question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Suggestion: implementing auto-mocking capabilities

See original GitHub issue

Hi,

The testing package in golevelup is great, the easy functionality of createMock makes it easy to mock things without any effort; @jmcdo29 - saw your issue at nest repo (https://github.com/nestjs/nest/pull/6277 - feat(testing): add auto-mocking capabilities) and thought maybe I can implement it, so I did.

My questions are (1) Do you still want this feature? (2) Is this the right repo to create a PR in?

Here is a code snippet example:

describe('Unit Test', () => {
  let someService: DeepMocked<SomeService>;

  beforeAll(() => {
    someService = Unit.createTestingService(SomeService)
      .mock(ClientService)
      .with({
        foo: () => Promise.resolve({ token: '' }),
      })
      .mock(PayService)
      .with({
        bar: () => 'dogs are awesome',
      } as any)
      .compile();
  });

  describe('Test Something', () => {
    test('then do something', () => {
      expect(1).toBe(1);
    });
  });
});

Where all the rest of the dependencies of the class SomeService are auto-mocked, everything is using createMock() of course

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:18 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
WonderPandacommented, Nov 11, 2021

That sounds awesome, thanks @omermorad!

0reactions
underfiskcommented, Jan 21, 2022

The auto mock will be available when #342 is released

Read more comments on GitHub >

github_iconTop Results From Across the Web

CLI feature suggestion : debug automocking · Issue #649
We had numerous problems when writing / executing our specs and most of the hassle was coming from the automocking feature: A module...
Read more >
How to automock a module with Jest and make assertions ...
I have to do this for any function within our api that might be called by (the) function(s) under test, because I'm bypassing...
Read more >
Mocking | Guide
This is commonly referred to as mocking. Vitest provides utility functions to help you out through its vi helper. You can import {...
Read more >
Choose Your Constructor with JustMock Automocking
To show this new feature, I created a simple class that has multiple constructors, as shown in Listing 1. public class ManyConstructors {...
Read more >
Introducing Auto-Mocking in SwaggerHub
The VirtServer Integration in SwaggerHub integrates basic virt functionality directly into the API lifecycle. When enabled, the VirtServer Integration ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found