refactor: Use early return pattern to avoid nested conditions (#302)

This commit is contained in:
Jongwoo Han
2022-12-16 23:05:54 +09:00
committed by GitHub
parent 6edd4406fa
commit bb5ff97ab9
4 changed files with 29 additions and 30 deletions

View File

@ -162,7 +162,7 @@ describe('isCacheFeatureAvailable', () => {
expect(functionResult).toBeFalsy();
});
it('should throw when cache feature is unavailable and GHES is used', () => {
it('should warn when cache feature is unavailable and GHES is used', () => {
//Arrange
isFeatureAvailableSpy.mockImplementation(() => {
return false;
@ -170,10 +170,11 @@ describe('isCacheFeatureAvailable', () => {
process.env['GITHUB_SERVER_URL'] = 'https://nongithub.com';
let errorMessage =
let warningMessage =
'Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.';
//Act + Assert
expect(() => cacheUtils.isCacheFeatureAvailable()).toThrow(errorMessage);
expect(cacheUtils.isCacheFeatureAvailable()).toBeFalsy();
expect(warningSpy).toHaveBeenCalledWith(warningMessage);
});
});