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

220
Views
Mocha js Uncaught TypeError: no se pueden leer las propiedades de undefined (leyendo 'debería')

Así que estoy tratando de probar mi API y con mocha js y recibo este error.

 SAMPLE unit test 1) should return posts with tag tech sorted by likes 0 passing (26ms) 1 failing 1) SAMPLE unit test should return home page: Uncaught TypeError: Cannot read properties of undefined (reading 'should') at Test.<anonymous> (test\get_info.test.js:22:18) at Test.assert (node_modules\supertest\lib\test.js:172:8) at localAssert (node_modules\supertest\lib\test.js:120:14) at C:\Users\tiktk\Desktop\Fetch\node_modules\supertest\lib\test.js:125:7 at Test.Request.callback (node_modules\superagent\lib\node\index.js:927:3) at ClientRequest.<anonymous> (node_modules\superagent\lib\node\index.js:844:12) at ClientRequest.emit (node:events:390:28) at Socket.socketErrorListener (node:_http_client:447:9) at Socket.emit (node:events:390:28) at emitErrorNT (node:internal/streams/destroy:157:8) at emitErrorCloseNT (node:internal/streams/destroy:122:3) at processTicksAndRejections (node:internal/process/task_queues:83:21)

Tengo todas las dependencias instaladas y actualizadas pero sigo recibiendo ese error.

 var supertest = require("supertest"); var should = require("should"); var server = supertest.agent("http://127.0.0.1:3000"); describe("Api unit test",function(){ it("should return posts with tag tech sorted by likes",function(done){ server .get("/api/posts?tags=tech&sortBy=likes&direction=desc") .expect("Content-type",/json/) .expect(200) .end(function(res){ // HTTP status should be 200 res.status.should.equal(200); // Error key should be false. res.body.error.should.equal(false); done(); }); }); });

El enlace debería devolver un montón de objetos en una matriz como un archivo JSON ordenado por me gusta (en este caso)

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

0

Lo más probable es que el error provenga del hecho de que res.body.error no está definido cuando no tiene un error. En cuyo caso, su prueba debería ser algo como:

 res.body.should.not.have.property('error')

Para confirmar mi hipótesis, debe consola. registrar el contenido de res.body antes de verificar el error.

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!