diff --git a/packages/workspace/src/generators/remove/lib/update-jest-config.spec.ts b/packages/workspace/src/generators/remove/lib/update-jest-config.spec.ts index bc018577684fe..a3d52906ef9da 100644 --- a/packages/workspace/src/generators/remove/lib/update-jest-config.spec.ts +++ b/packages/workspace/src/generators/remove/lib/update-jest-config.spec.ts @@ -91,4 +91,24 @@ describe('updateRootJestConfig', () => { expect(rootJestConfig).toMatchSnapshot(); }); + + it('should handle not having a root jest config file', async () => { + // ARRANGE + tree.delete('jest.config.ts'); + + await libraryGenerator(tree, { + name: 'test', + bundler: 'vite', + unitTestRunner: 'vitest', + }); + + // ACT + expect(() => + updateJestConfig( + tree, + { projectName: 'test', skipFormat: false, forceRemove: false }, + readProjectConfiguration(tree, 'test') + ) + ).not.toThrow(); + }); }); diff --git a/packages/workspace/src/generators/remove/lib/update-jest-config.ts b/packages/workspace/src/generators/remove/lib/update-jest-config.ts index 1cf5aef33a8f5..8ac17f22b0f90 100644 --- a/packages/workspace/src/generators/remove/lib/update-jest-config.ts +++ b/packages/workspace/src/generators/remove/lib/update-jest-config.ts @@ -69,6 +69,7 @@ export function updateJestConfig( const rootConfigPath = findRootJestConfig(tree); if ( + !rootConfigPath || !tree.exists(rootConfigPath) || !tree.exists(join(projectConfig.root, 'jest.config.ts')) || isUsingUtilityFunction(tree) ||