Browse Source

Update generators package tests

Renamed 'targetOption' to 'targetProject' in the ChangeThemeGeneratorSchema and updated related test usage. Added a mock for wrapAngularDevkitSchematic in the generator tests and improved the test to check the generator's return value. Set Jest test environment to 'node' in the generators package config.
pull/23460/head
Fahri Gedik 8 months ago
parent
commit
320bf8fa06
  1. 1
      npm/ng-packs/packages/generators/jest.config.ts
  2. 13
      npm/ng-packs/packages/generators/src/generators/change-theme/generator.spec.ts
  3. 2
      npm/ng-packs/packages/generators/src/generators/change-theme/schema.d.ts

1
npm/ng-packs/packages/generators/jest.config.ts

@ -2,6 +2,7 @@
export default {
displayName: 'generators',
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},

13
npm/ng-packs/packages/generators/src/generators/change-theme/generator.spec.ts

@ -4,17 +4,22 @@ import { Tree, readProjectConfiguration } from '@nx/devkit';
import { changeThemeGenerator } from './generator';
import { ChangeThemeGeneratorSchema } from './schema';
// Mock the wrapAngularDevkitSchematic function
jest.mock('@nx/devkit/ngcli-adapter', () => ({
wrapAngularDevkitSchematic: jest.fn(() => jest.fn()),
}));
describe('change-theme generator', () => {
let tree: Tree;
const options: ChangeThemeGeneratorSchema = { name: 'test' };
const options: ChangeThemeGeneratorSchema = { name: 1, targetProject: 'test' };
beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
});
it('should run successfully', async () => {
await changeThemeGenerator(tree, options);
const config = readProjectConfiguration(tree, 'test');
expect(config).toBeDefined();
const result = await changeThemeGenerator(tree, options);
expect(result).toBeDefined();
expect(typeof result).toBe('function');
});
});

2
npm/ng-packs/packages/generators/src/generators/change-theme/schema.d.ts

@ -1,5 +1,5 @@
export interface ChangeThemeGeneratorSchema {
name: number;
targetOption: string;
targetProject: string;
localPath?: string;
}

Loading…
Cancel
Save