Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
¿No se puede inyectar/simular un documento en mi archivo js de prueba unitaria con Jest?

En primer lugar, soy un desarrollador de BE. Tenemos algunos archivos js en nuestro proyecto para los que queremos escribir algunas pruebas unitarias. La broma es el marco que elegimos. Estoy tratando de escribir pruebas unitarias para el siguiente archivo:

 "use strict"; // when dialog gets injected $(document).on("foundation-contentloaded", function (e) { // if there is already an initial value make sure the according target element becomes visible $("[data-dialog-checkbox-showhide]", e.target).each(function () { showHide($(this)); }); }); $(document).on("change", "[data-dialog-checkbox-showhide]", function () { showHide($(this)); }); function showHide(el) { // get the selector to find the target elements. its stored as data-.. attribute var target = el.data("dialogCheckboxShowhideTarget"); // is checkbox checked? var checked = el.prop('checked'); if (checked) { $(target).each(function () { // if checkbox is checked, we set the value to empty string. $(this).val('').attr('aria-required', false); // Hide input field as well as label. $(this).parent().hide(); }); } else { $(target).each(function () { $(this).attr('aria-required', true); // Show input field as well as label. $(this).parent().show(); }); } } })(document, Granite.$);

He escrito la siguiente prueba solo para verificar si se llama al método showhide:

 describe("checkboxshowhide method:", () => { test("should call showHide method", () => { const $ = require('jquery'); // Set up our document body document.body.innerHTML = '<div>' + ' <span id="username" />' + ' <button id="button" />' + '</div>'; expect(showHide()).toBeCalled(); }); });

Sin embargo, estoy recibiendo un error.

[INFO] [nodejs] ReferenceError: el documento no está definido [INFO] [nodejs] > 51 | })(documento, Granito.$);

Además, algunos consejos sobre cómo puedo probar otros métodos serían realmente útiles.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Me había perdido siguiendo en la parte superior del archivo de prueba.

 /** * @jest-environment jsdom */

Pensé que este era un comentario como javadoc.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!