# jest/no-jasmine-globals

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

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.

| Jasmine | Jest |
| --- | --- |
| `spyOn`, `spyOnProperty` | `jest.spyOn` |
| `fail` | Throw an error |
| `pending` | `test.skip` |
| `jasmine.any`, `anything`, `arrayContaining`, `objectContaining`, `stringMatching` | The same name on `expect` |
| `jasmine.createSpy` | `jest.fn` |
| `jasmine.addMatchers` | `expect.extend` |
| `jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000` | `jest.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)`.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

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

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 4} */}
```js
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();
});
```

Not reported:

{/* good */}
```js
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:

{/* good */}
```js
import { fail } from "./helpers";

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