From 3e97e607a7c54e958edce7cd8d3aa5fabe130b0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Roma=C5=84ski?= Date: Thu, 12 Dec 2024 14:56:56 +0100 Subject: [PATCH] tests: separate testing of calls from testing of return value --- .../src/plugin/caching.unit-test.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/projects/nx-verdaccio/src/plugin/caching.unit-test.ts b/projects/nx-verdaccio/src/plugin/caching.unit-test.ts index 1e676d0..52d2901 100644 --- a/projects/nx-verdaccio/src/plugin/caching.unit-test.ts +++ b/projects/nx-verdaccio/src/plugin/caching.unit-test.ts @@ -159,20 +159,21 @@ describe('caching', () => { }; - // beforeEach((): void => { - // existsSyncSpy = vi.spyOn(cachingUtils, 'cacheKey'); - // }); - - afterEach((): void => { - existsSyncSpy.mockRestore(); + beforeEach((): void => { + process.env.NX_CACHE_PROJECT_GRAPH = 'true'; }); - it('should call cacheKey with the correct arguments and return from json file', (): void => { + it('should call exist sync with the correct arguments', (): void => { process.env.NX_CACHE_PROJECT_GRAPH = 'true'; - const targetsCacheResult = readTargetsCache('test'); + readTargetsCache('test'); expect(existsSyncSpy).toHaveBeenCalledWith('test'); expect(existsSyncSpy).toHaveBeenCalledTimes(1); expect(readJsonFileSpy).toHaveBeenCalledTimes(1); + }); + + it('should return target cache from json file', (): void => { + process.env.NX_CACHE_PROJECT_GRAPH = 'true'; + const targetsCacheResult = readTargetsCache('test'); expect(targetsCacheResult).toStrictEqual({'mockKey': mockProjectConfiguration}); }); });