-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #548 from Green-Software-Foundation/unit-tests-util
Unit tests util
- Loading branch information
Showing
8 changed files
with
223 additions
and
16 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const mockWarn = jest.fn(); | ||
const mockError = jest.fn(); | ||
|
||
jest.mock('../../../util/logger', () => ({ | ||
logger: { | ||
warn: mockWarn, | ||
error: mockError, | ||
}, | ||
})); | ||
|
||
import {andHandle} from '../../../util/helpers'; | ||
import {ERRORS} from '../../../util/errors'; | ||
|
||
const {WriteFileError} = ERRORS; | ||
|
||
describe('util/helpers: ', () => { | ||
describe('andHandle(): ', () => { | ||
afterEach(() => { | ||
mockWarn.mockReset(); | ||
mockError.mockReset(); | ||
}); | ||
|
||
it('logs error and warn in case of error is unknown.', () => { | ||
const message = 'mock-message'; | ||
const MockError = class extends Error {}; | ||
|
||
andHandle(new MockError(message)); | ||
expect(mockWarn).toHaveBeenCalledTimes(1); | ||
expect(mockError).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('logs error in case of error is unknown.', () => { | ||
const message = 'mock-message'; | ||
|
||
andHandle(new WriteFileError(message)); | ||
expect(mockWarn).toHaveBeenCalledTimes(0); | ||
expect(mockError).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
}); |
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
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