Skip to content

Commit

Permalink
fix: adjust tests for CxErrorHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelfras committed Sep 3, 2024
1 parent e6b9edc commit 4bb832c
Showing 1 changed file with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ import { ErrorActionService } from './error-action.service';
describe('CxErrorHandlerEffect', () => {
let effect: CxErrorHandlerEffect;
let actions$: Observable<Action>;
let effectsErrorHandlerService: jasmine.SpyObj<ErrorActionService>;
let errorActionService: jasmine.SpyObj<ErrorActionService>;
let featureConfigService: FeatureConfigService;

beforeEach(() => {
const effectsErrorHandlerServiceSpy = jasmine.createSpyObj(
'EffectsErrorHandlerService',
['handleError', 'filterActions']
);
const errorActionServiceSpy = jasmine.createSpyObj('ErrorActionService', [
'handle',
'isErrorAction',
]);
TestBed.configureTestingModule({
providers: [
CxErrorHandlerEffect,
FeatureConfigService,
provideMockActions(() => actions$),
{
provide: ErrorActionService,
useValue: effectsErrorHandlerServiceSpy,
useValue: errorActionServiceSpy,
},
],
});

effect = TestBed.inject(CxErrorHandlerEffect);
actions$ = TestBed.inject(Actions);
effectsErrorHandlerService = TestBed.inject(
errorActionService = TestBed.inject(
ErrorActionService
) as jasmine.SpyObj<ErrorActionService>;
featureConfigService = TestBed.inject(FeatureConfigService);
Expand All @@ -54,29 +54,27 @@ describe('CxErrorHandlerEffect', () => {
error: new Error(),
};

effectsErrorHandlerService.isErrorAction.and.returnValue(true);
errorActionService.isErrorAction.and.returnValue(true);

actions$ = of(mockErrorAction);

effect.error$.subscribe();

expect(effectsErrorHandlerService.handle).toHaveBeenCalledWith(
mockErrorAction
);
expect(errorActionService.handle).toHaveBeenCalledWith(mockErrorAction);
});

it('should not handle non-error action', () => {
const mockNonErrorAction = {
type: 'SOME_ACTION',
};

effectsErrorHandlerService.isErrorAction.and.returnValue(false);
errorActionService.isErrorAction.and.returnValue(false);

actions$ = of(mockNonErrorAction);

effect.error$.subscribe();

expect(effectsErrorHandlerService.handle).not.toHaveBeenCalled();
expect(errorActionService.handle).not.toHaveBeenCalled();
});
});
});
Expand All @@ -89,10 +87,10 @@ describe('CxErrorHandlerEffect', () => {
type: 'ERROR_ACTION_TYPE',
error: new Error(),
};
effectsErrorHandlerService.isErrorAction.and.returnValue(true);
errorActionService.isErrorAction.and.returnValue(true);
actions$ = of(mockErrorAction);
effect.error$.subscribe();
expect(effectsErrorHandlerService.handle).not.toHaveBeenCalled();
expect(errorActionService.handle).not.toHaveBeenCalled();
});
});
});

0 comments on commit 4bb832c

Please sign in to comment.