Skip to content

Commit

Permalink
fix: Added fix/add-validation-event-param-test-oas-web-api (#1819)
Browse files Browse the repository at this point in the history
Co-authored-by: Ivy Feraco <ivy@laboratoria.la>
  • Loading branch information
vivieall and Ivy Feraco authored May 16, 2024
1 parent d23b3f2 commit 8fc28d3
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions projects/02-dataverse/tests-read-only/oa/oa-web-api.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const renderCode = fs.readFileSync("src/view.js", "utf8");
const mainAst = acorn.parse(mainCode, { ecmaVersion: 2020, sourceType: "module" });
const ast = acorn.parse(renderCode, { ecmaVersion: 2020, sourceType: "module", program: mainAst});

const getASTMetrics = (node, [

const getASTMetrics = (node, [
querySelectorCalls=[],
getElementByIdCalls=[],
addEventListenerCalls=[],
Expand All @@ -17,7 +17,7 @@ const getASTMetrics = (node, [
innerHTMLs=[],
createElementCalls=[],
templateCalls=[] ]) => {

if (
node.type === "CallExpression" &&
node.callee.type === "MemberExpression" &&
Expand Down Expand Up @@ -66,8 +66,8 @@ const getASTMetrics = (node, [
createElementCalls.push(node);
}

if (node.type === "VariableDeclaration" &&
node.declarations &&
if (node.type === "VariableDeclaration" &&
node.declarations &&
node.declarations[0].init &&
node.declarations[0].init['type'] === "TemplateLiteral"){
templateCalls.push(node);
Expand Down Expand Up @@ -127,7 +127,10 @@ describe('Manejo de eventos del DOM', () => {
it('Se registra un Event Listener con un parametro de evento', () => {
expect(
addEventListenerCalls.some((node) => {
if (node.arguments[1].params.length === 0) return false;
// si el segundo argumento es una referencia a una función por su nombre
if (node.arguments[1].type === 'Identifier') return true;
// si la función tiene parámetros definidos
if (!node.arguments[1].params || node.arguments[1].params.length === 0) return false;
// que existe un param tipo { target } { currentTarget }
const hasTargetParam = node.arguments[1].params[0].type === 'ObjectPattern' && (
node.arguments[1].params[0].properties[0].key.name === ('target') ||
Expand All @@ -148,7 +151,7 @@ describe('Manipulación dinámica del DOM', () => {

it('Existe manipulación dinamica mediante createElement o template strings', () => {
expect(createElementCalls.length || templateCalls.length).toBeGreaterThan(0);
});
});

});

Expand Down

0 comments on commit 8fc28d3

Please sign in to comment.