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

811
Views
Acceder a jasmine con testRunner configurado en jest-circus da como resultado: ReferenceError: jasmine no está definido

Por defecto, jest te permite simplemente acceder a jasmine globalmente. Pero tan pronto como cambia el testRunner a jest-circus , jasmine no está definido. El siguiente es un ejemplo mínimo y reproducible:

babel.config.js

 module.exports = { presets: [["@babel/preset-env", { targets: { node: "current" } }]], };

jazmín.spec.js

 it("check jasmine", () => { console.log(jasmine); });

jest.config.js

 module.exports = { rootDir: ".", testRunner: "jest-circus/runner", };

paquete.json

 { "name": "test-jest", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "jest" }, "author": "", "license": "ISC", "dependencies": { "@babel/core": "^7.12.10", "@babel/preset-env": "^7.12.11", "babel-jest": "^26.6.3", "jest": "^26.6.3", "jest-circus": "^26.6.3" } }

La ejecución de esta prueba generará el siguiente resultado:

 $ npm test > test-jest@1.0.0 test /Users/yusufaran/Projects/test/test-jest > jest FAIL ./jasmine.spec.js ✕ check jasmine (1 ms) ● check jasmine ReferenceError: jasmine is not defined 1 | it("check jasmine", () => { > 2 | console.log(jasmine); | ^ 3 | }); 4 | at Object.<anonymous> (jasmine.spec.js:2:15) Test Suites: 1 failed, 1 total Tests: 1 failed, 1 total Snapshots: 0 total Time: 1.01 s Ran all test suites. npm ERR! Test failed. See above for more details.

Si elimina/comenta la línea testRunner en jest.config.js (para que recurra al ejecutor predeterminado), funciona como se esperaba.

Pregunta

¿Cómo puedo acceder al objeto jasmine global con testRunner configurado en jest-circus/runner ? Si no puedo, ¿por qué?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

No puedes acceder a jasmine cuando usas jest-circus. Esto es por diseño. jest-circus es un nuevo corredor de pruebas que se creó desde cero. Imita la funcionalidad de jasmine para definir pruebas (es decir, describe it todo excepto expect aserciones y espías).

Si depende de jasmine, entonces npm install -D jest-jasmine2 y utilícelo en su configuración de jest:

 { testRunner: 'jest-jasmine2' }
over 4 years ago · Santiago Trujillo Report

0

Solo agregando testRunner: 'jasmine2' a jest.config.js me funcionó

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