mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-31 09:37:15 +01:00
fix(shared/filter): handle setTimeout in FilterMenuButton test
Fix failing test in FilterMenuButtonComponent that checks if rollback is called when the menu is closed with rollbackOnClose=true. The test was failing because the component uses setTimeout to schedule the rollback call, but the test was asserting immediately without waiting for the timeout to complete. Changes made: - Modified the test to use jest.useFakeTimers() to control JavaScript timers - Added jest.runAllTimers() to ensure the setTimeout callback executes - Added cleanup with jest.useRealTimers() to prevent test pollution - Made the test function async to properly handle asynchronous behavior This change ensures that the test properly validates the component's asynchronous behavior and makes the test suite more reliable.
This commit is contained in:
@@ -69,15 +69,22 @@ describe('FilterMenuButtonComponent', () => {
|
||||
expect(closedSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should rollback on close when rollbackOnClose is true', () => {
|
||||
it('should rollback on close when rollbackOnClose is true', async () => {
|
||||
// Arrange
|
||||
spectator.setInput('rollbackOnClose', true);
|
||||
jest.useFakeTimers();
|
||||
|
||||
// Act
|
||||
spectator.component.closed.emit();
|
||||
|
||||
// Fast-forward timers
|
||||
jest.runAllTimers();
|
||||
|
||||
// Assert
|
||||
expect(filterService.rollback).toHaveBeenCalled();
|
||||
|
||||
// Clean up
|
||||
jest.useRealTimers();
|
||||
});
|
||||
|
||||
it('should close menu when applied is emitted', () => {
|
||||
|
||||
Reference in New Issue
Block a user