Performance: Unit testing controllers
LOW IMPACT
Unit testing controllers affects development speed and feedback loop but does not impact runtime page load or rendering performance.
describe('UserController', () => { let controller: UserController; const mockUserService = { getUser: jest.fn().mockResolvedValue({ id: '1', name: 'Test' }) }; beforeEach(() => { controller = new UserController(mockUserService as any); }); it('should return user data', async () => { const result = await controller.getUser('1'); expect(result).toEqual({ id: '1', name: 'Test' }); }); });
describe('UserController', () => { let controller: UserController; beforeEach(async () => { const module = await Test.createTestingModule({ controllers: [UserController], imports: [DatabaseModule, HttpModule], providers: [UserService], }).compile(); controller = module.get<UserController>(UserController); }); it('should return user data', async () => { const result = await controller.getUser('1'); expect(result).toBeDefined(); }); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Full module loading in tests | 0 | 0 | 0 | [X] Bad |
| Mocking dependencies in tests | 0 | 0 | 0 | [OK] Good |