Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

813
Visualizações
Accessing jasmine with testRunner set to jest-circus results in: ReferenceError: jasmine is not defined

On default jest allows you to simply access jasmine globally. But as soon as you switch the testRunner to jest-circus, jasmine is undefined. Following is a minimal, reproducible example:

babel.config.js

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

jasmine.spec.js

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

jest.config.js

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

package.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"
  }
}

Running this test will cause following output:

$ 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.

If you remove/comment the testRunner line in jest.config.js (so it fallbacks to the default runner) it works as expected.

Question

How can I access global jasmine object with testRunner set to jest-circus/runner? If I can't, why?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You can’t access jasmine when you use jest-circus. This is by design. jest-circus is a new test runner that was built from scratch. It mimics jasmine functionality for defining tests (i.e., describe, it, everything except expect assertions and spies).

If you depend on jasmine, then npm install -D jest-jasmine2 and use it in your jest config:

{
  testRunner: 'jest-jasmine2'
}
over 4 years ago · Santiago Trujillo Relatório

0

Just adding testRunner: 'jasmine2' to jest.config.js did the trick for me

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda