Skip to content

Commit

Permalink
tests: separate testing of calls from testing of return value
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianRomanski committed Dec 12, 2024
1 parent 89baebf commit 3e97e60
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions projects/nx-verdaccio/src/plugin/caching.unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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});
});
});
Expand Down

0 comments on commit 3e97e60

Please sign in to comment.