Closed gparlakov closed 2 months ago
✅ Tests will run for this PR. Once they succeed it can be merged.
AutoSpy walks the prototype and creates a spy (jest.fn) and the test.get is a dependency injection tool (i.e. resolve and give me an isnstance for this token).
Autospy essentially does this https://github.com/podkrepi-bg/api/blob/39e39a856d2de27b9b6944ff9382a65dafd25249/apps/api/src/campaign/campaign.controller.spec.ts#L34
The docs seem to talk about mocking but not show a mechanism to mock instances. Or did I miss something?
What do you feel is the overlap here?
On Sat, Jun 22, 2024, 2:10 PM Aleksandar Petkov @.***> wrote:
@.**** commented on this pull request.
In apps/api/src/campaign-application/campaign-application.controller.spec.ts https://github.com/podkrepi-bg/api/pull/647#discussion_r1649630855:
@@ -0,0 +1,71 @@ +import { Test, TestingModule } from @./testing' +import { CampaignApplicationController } from './campaign-application.controller' +import { CampaignApplicationService } from './campaign-application.service' +import { SpyOf, autoSpy } from @./testing' + +describe('CampaignApplicationController', () => {
- let controller: CampaignApplicationController
- let service: SpyOf
- beforeEach(async () => {
- service = autoSpy(CampaignApplicationService)
How is autoSpy different, than module.get
(CampaignApplicationService)? Seems redundant to me. Docs in NestJS also shows similar way to mock the Service classes link https://docs.nestjs.com/fundamentals/testing#testing-utilities
— Reply to this email directly, view it on GitHub https://github.com/podkrepi-bg/api/pull/647#pullrequestreview-2133698487, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2SEV6YTKP6KCWZLHMZTBTZIVLSFAVCNFSM6AAAAABJULSIQ6VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDCMZTGY4TQNBYG4 . You are receiving this because you authored the thread.Message ID: @.***>
AutoSpy walks the prototype and creates a spy (jest.fn) and the test.get is a dependency injection tool (i.e. resolve and give me an isnstance for this token). Autospy essentially does this https://github.com/podkrepi-bg/api/blob/39e39a856d2de27b9b6944ff9382a65dafd25249/apps/api/src/campaign/campaign.controller.spec.ts#L34 The docs seem to talk about mocking but not show a mechanism to mock instances. Or did I miss something? What do you feel is the overlap here?
I was rather curious, because I have not seen this practice before, and probably got a bit confused, by the implementation. Though I admit I should've put a bit more thought at what autoSpy does, before bothering you explaining it to me. Sorry for that.
New endpoints
campaign-application/create campaign-application/find-all campaign-application/find-one campaign-application/update