mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-29 00:51:29 +08:00
Updates declaration to include specific types for the logger object.
This commit is contained in:
16
types/jquery-mockjax/index.d.ts
vendored
16
types/jquery-mockjax/index.d.ts
vendored
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user