Updates declaration to include specific types for the logger object.

This commit is contained in:
James Johnson
2018-06-05 19:17:26 -05:00
parent b000f9a36b
commit 3b60e1932f
2 changed files with 43 additions and 2 deletions

View File

@@ -9,6 +9,20 @@
/// <reference types="jquery" />
type MockJaxLoggingFunction = (message?: any, ...additionalParameters: any[]) => void;
interface MockJaxStandardLogger {
error?: MockJaxLoggingFunction;
warn?: MockJaxLoggingFunction;
info?: MockJaxLoggingFunction;
log?: MockJaxLoggingFunction;
debug?: MockJaxLoggingFunction;
}
interface MockJaxCustomLogger {
[key: string]: MockJaxLoggingFunction;
}
interface MockJaxSettingsHeaders {
[key: string]: string;
}
@@ -36,7 +50,7 @@ interface MockJaxSettings {
onAfterSuccess?: Function;
onAfterError?: Function;
onAfterComplete?: Function;
logger?: any;
logger?: MockJaxStandardLogger | MockJaxCustomLogger;
logLevelMethods?: string[];
namespace?: string;
throwUnmocked?: boolean;

View File

@@ -193,7 +193,7 @@ class Tests {
});
});
t('Custom logger gets called', (assert) => {
t('Standard logger type gets called', (assert) => {
let done = assert.async();
let wasLoggerCalled = false;
@@ -213,6 +213,33 @@ class Tests {
$.mockjax(settings);
$.ajax({
url: '/custom-logging-function',
error: self._noErrorCallbackExpected,
complete: (xhr) => {
assert.equal(wasLoggerCalled, true, 'Standard logger was called');
done();
}
});
});
t('Custom logger object gets called', (assert) => {
let done = assert.async();
let wasLoggerCalled = false;
let logFunction = () => wasLoggerCalled = true;
let settings: MockJaxSettings = {
url: '/custom-logging-function',
logging: true,
logger: {
customName: logFunction
},
logLevelMethods: ['customName', 'customName', 'customName', 'customName', 'customName']
};
$.mockjax(settings);
$.ajax({
url: '/custom-logging-function',
error: self._noErrorCallbackExpected,