-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3ad5d8
commit 8dd782f
Showing
6 changed files
with
148 additions
and
8 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,32 @@ | ||
'use strict'; | ||
|
||
/** | ||
* @file A stub test file to give coverage to the JSDocs types file. | ||
*/ | ||
|
||
const { | ||
CUSTOMLOGGER, | ||
OPTIONS, | ||
SPLASHER, | ||
AUTOUPDATE, | ||
NEWWINDOW | ||
} = require('../api-type-definitions.cjs'); | ||
|
||
describe('api-type-definitions.cjs', () => { | ||
test('Stub for coverage', () => { | ||
expect(CUSTOMLOGGER) | ||
.toEqual(undefined); | ||
|
||
expect(OPTIONS) | ||
.toEqual(undefined); | ||
|
||
expect(SPLASHER) | ||
.toEqual(undefined); | ||
|
||
expect(AUTOUPDATE) | ||
.toEqual(undefined); | ||
|
||
expect(NEWWINDOW) | ||
.toEqual(undefined); | ||
}); | ||
}); |
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,100 @@ | ||
'use strict'; | ||
|
||
/** | ||
* @file Unit tests for helper functions. | ||
*/ | ||
|
||
const { LIBRARY_LOG_PREFIX } = require('../../src/constants.cjs'); | ||
const helpers = require('../../src/helpers.cjs'); | ||
|
||
describe('helpers.cjs', () => { | ||
let customLogger; | ||
let options; | ||
const consoleError = console.error; | ||
|
||
beforeEach(() => { | ||
console.error = vi.fn(); | ||
customLogger = vi.fn(); | ||
options = { | ||
verbose: true, | ||
customLogger | ||
}; | ||
}); | ||
|
||
afterEach(() => { | ||
vi.clearAllMocks(); | ||
console.error = consoleError; | ||
}); | ||
|
||
describe('throwError', () => { | ||
const message = 'This is the message'; | ||
const error = new Error('This is the error'); | ||
|
||
test('Does nothing if nothing passed in', () => { | ||
helpers.throwError(); | ||
|
||
expect(options.customLogger) | ||
.not.toHaveBeenCalled(); | ||
|
||
expect(console.error) | ||
.not.toHaveBeenCalled(); | ||
}); | ||
|
||
test('Calls customLogger with message and error', () => { | ||
helpers.throwError(options, message, error); | ||
|
||
expect(options.customLogger) | ||
.toHaveBeenCalledWith(message, error); | ||
|
||
expect(console.error) | ||
.not.toHaveBeenCalled(); | ||
}); | ||
|
||
test('Calls customLogger with just message', () => { | ||
helpers.throwError(options, message); | ||
|
||
expect(options.customLogger) | ||
.toHaveBeenCalledWith(message); | ||
|
||
expect(console.error) | ||
.not.toHaveBeenCalled(); | ||
}); | ||
|
||
test('Calls console.error with message and error', () => { | ||
delete options.customLogger; | ||
helpers.throwError(options, message, error); | ||
|
||
expect(console.error) | ||
.toHaveBeenCalledWith(LIBRARY_LOG_PREFIX, message, error); | ||
|
||
expect(options.customLogger) | ||
.toEqual(undefined); | ||
}); | ||
|
||
test('Calls console.error with just message', () => { | ||
delete options.customLogger; | ||
helpers.throwError(options, message); | ||
|
||
expect(console.error) | ||
.toHaveBeenCalledWith(LIBRARY_LOG_PREFIX, message); | ||
|
||
expect(options.customLogger) | ||
.toEqual(undefined); | ||
}); | ||
}); | ||
|
||
describe('requiredFunctionMissing', () => { | ||
test('Throws error when called', () => { | ||
let message; | ||
|
||
try { | ||
message = helpers.requiredFunctionMissing(); | ||
} catch (error) { | ||
message = error; | ||
} | ||
|
||
expect(message) | ||
.toEqual('ERROR: Required function missing.'); | ||
}); | ||
}); | ||
}); |
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