Suggestion: implementing auto-mocking capabilities
See original GitHub issueHi,
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:
- Created 2 years ago
- Reactions:1
- Comments:18 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
That sounds awesome, thanks @omermorad!
The auto mock will be available when #342 is released