mirror of
https://github.com/javascript-obfuscator/javascript-obfuscator
synced 2026-08-09 12:42:29 +00:00
Added tests for a valid bind call of console.log methods of ConsoleOutputDisableTemplate
This commit is contained in:
+31
-2
@@ -44,13 +44,15 @@ const getPartialConsoleObjectGlobalVariableTemplate: () => string = () => `
|
||||
/**
|
||||
* @param templateData
|
||||
* @param {string} callsControllerFunctionName
|
||||
* @param {string} consoleMethod
|
||||
* @param {keyof Console} consoleMethod
|
||||
* @param {string} additionalCode
|
||||
* @returns {Function}
|
||||
*/
|
||||
function getFunctionFromTemplate (
|
||||
templateData: any,
|
||||
callsControllerFunctionName: string,
|
||||
consoleMethod: keyof Console
|
||||
consoleMethod: keyof Console,
|
||||
additionalCode: string = ''
|
||||
): Function {
|
||||
const formattedTemplate: string = format(ConsoleOutputDisableTemplate(), templateData);
|
||||
|
||||
@@ -67,6 +69,8 @@ function getFunctionFromTemplate (
|
||||
|
||||
console.${consoleMethod}(1);
|
||||
console.${consoleMethod}.toString();
|
||||
|
||||
${additionalCode}
|
||||
`);
|
||||
}
|
||||
|
||||
@@ -186,6 +190,31 @@ describe('ConsoleOutputDisableTemplate', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('`bind` call', () => {
|
||||
consoleMethods.forEach((consoleMethodName: keyof Console, index: number) => {
|
||||
describe(`Variant #${index + 1}: \`console.${consoleMethodName}\` call`, () => {
|
||||
let testFunc: () => void;
|
||||
|
||||
beforeEach(() => {
|
||||
testFunc = () => getFunctionFromTemplate(
|
||||
{
|
||||
consoleLogDisableFunctionName,
|
||||
callControllerFunctionName,
|
||||
globalVariableTemplate: GlobalVariableTemplate1(),
|
||||
},
|
||||
callControllerFunctionName,
|
||||
consoleMethodName,
|
||||
`console.${consoleMethodName}.bind();`
|
||||
)();
|
||||
});
|
||||
|
||||
it(`should does not throw error during \`console.${consoleMethodName}.bind\` call`, () => {
|
||||
assert.doesNotThrow(testFunc);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
consoleObjectStubs.forEach((stub: sinon.SinonStub) => stub.restore());
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user