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

214
Views
¿Cómo probar jQuery usando la afirmación de Chai-jQuery?

Estoy usando Mocha/Chai/Chai-jquery para probar el código escrito en Jquery. Y aunque he incluido jquery y chai-jquery en HTML, cuando ejecuto esta prueba:

 it("is focused", function () { expect($("#movie")).should.have.focus();});

usando la afirmación de chai-jquery:

 (expect = require('chai-jquery').expect)

me sale este error:

 TypeError: expect(...).should.have.focus is not a function

Entonces, ¿cómo puedo configurar esto para usar la afirmación de Chai-jquery como se muestra aquí ? Aquí está mi código:

html:

 <body> <div id="mocha"></div> <script src="node_modules/mocha/mocha.js"></script> <script src="node_modules/jquery/src/jquery.js"></script> <script src="node_modules/chai/chai.js"></script> <script src="node_modules/chai-jquery/chai-jquery.js"></script> <script> mocha.ui('bdd'); mocha.reporter('html'); var expect = chai.expect; </script> <script src="script.js"></script> <script src="test.js"></script> <script> { mocha.run(); } </script> <input id="movie"/> </body>

secuencia de comandos.js:

 $(document).ready(function() { $("#movie").focus(); //etc });

prueba.js:

 var jsdom = require('jsdom'); var document = jsdom.jsdom(""); var window = document.defaultView; global.window = window global.$ = require('jquery'); var assert = require('chai').assert, expect = require('chai').expect, should = require('chai').should(); describe("Search input test", function () { it("is in the DOM", function () { expect(searchInput).to.not.equal(null); }); // pass it("is a child of the body", function () { expect(searchInput.parentElement).to.equal(window.body); }); //pass it("is focused", function () { expect($("#movie")).should.have.focus(); }); // TypeError: expect(...).should.have.focus is not a function

});

about 4 years ago · Santiago Trujillo
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!