-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: CXSPA-6890 Create toggle and optimization options for propagati…
…ng errors to the server (#19021)
- Loading branch information
Showing
10 changed files
with
396 additions
and
53 deletions.
There are no files selected for viewing
27 changes: 22 additions & 5 deletions
27
...setup/ssr/error-handling/multi-error-handlers/propagating-to-server-error-handler.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,56 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { FeatureConfigService } from '@spartacus/core'; | ||
import { PROPAGATE_ERROR_TO_SERVER } from '../error-response/propagate-error-to-server'; | ||
import { PropagatingToServerErrorHandler } from './propagating-to-server-error-handler'; | ||
|
||
describe('PropagatingToServerErrorHandler', () => { | ||
describe('default factories', () => { | ||
let serverRespondingErrorHandler: PropagatingToServerErrorHandler; | ||
let propagatingToServerErrorHandler: PropagatingToServerErrorHandler; | ||
let featureConfigService: FeatureConfigService; | ||
let propagateErrorResponse: any; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
PropagatingToServerErrorHandler, | ||
FeatureConfigService, | ||
{ | ||
provide: PROPAGATE_ERROR_TO_SERVER, | ||
useValue: jest.fn(), | ||
}, | ||
], | ||
}); | ||
|
||
serverRespondingErrorHandler = TestBed.inject( | ||
propagatingToServerErrorHandler = TestBed.inject( | ||
PropagatingToServerErrorHandler | ||
); | ||
propagateErrorResponse = TestBed.inject(PROPAGATE_ERROR_TO_SERVER); | ||
featureConfigService = TestBed.inject(FeatureConfigService); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should propagate error', () => { | ||
it('should propagate error when propagateErrorsToServer is enabled', () => { | ||
jest | ||
.spyOn(featureConfigService, 'isEnabled') | ||
.mockImplementationOnce((val) => val === 'propagateErrorsToServer'); | ||
const error = new Error('test error'); | ||
|
||
serverRespondingErrorHandler.handleError(error); | ||
propagatingToServerErrorHandler.handleError(error); | ||
|
||
expect(propagateErrorResponse as jest.Mock).toHaveBeenCalledWith(error); | ||
}); | ||
|
||
it('should not propagate error when propagateErrorsToServer is disabled', () => { | ||
jest | ||
.spyOn(featureConfigService, 'isEnabled') | ||
.mockImplementationOnce((val) => !(val === 'propagateErrorsToServer')); | ||
const error = new Error('test error'); | ||
|
||
propagatingToServerErrorHandler.handleError(error); | ||
|
||
expect(propagateErrorResponse as jest.Mock).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.