jest/no-jasmine-globals

Disallow Jasmine globals such as jasmine.any, spyOn, fail and pending

fixable

Jest's default test runner doesn't define Jasmine's globals. A test that came from Jasmine and still calls fail(), spyOn() or jasmine.createSpy() throws a ReferenceError when it gets there. Jest has its own API for each of them.

JasmineJest
spyOn, spyOnPropertyjest.spyOn
failThrow an error
pendingtest.skip
jasmine.any, anything, arrayContaining, objectContaining, stringMatchingThe same name on expect
jasmine.createSpyjest.fn
jasmine.addMatchersexpect.extend
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000jest.setTimeout(5000)

Any other call to a jasmine method or assignment to a jasmine property is reported too.

--fix rewrites the five matchers, such as jasmine.any to expect.any, and jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000 to jest.setTimeout(5000).

Configure#

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"jest/no-jasmine-globals" = "error" # or "warn"

Examples#

example.js4 problems
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000;

test("saves the user", () => {
  spyOn(db, "insert");
  save({ name: "Ada" });
  expect(db.insert).toHaveBeenCalledWith(jasmine.any(Object));
});

test("exports to PDF", () => {
  pending();
});
example.jsNo problems
jest.setTimeout(5000);

test("saves the user", () => {
  jest.spyOn(db, "insert");
  save({ name: "Ada" });
  expect(db.insert).toHaveBeenCalledWith(expect.any(Object));
});

test.skip("exports to PDF", () => {});

Your own function with one of these names isn't reported:

example.jsNo problems
import { fail } from "./helpers";

test("rejects an empty name", () => {
  if (validate("")) {
    fail("an empty name passed");
  }
});