Skip to content

Latest commit

 

History

History
57 lines (47 loc) · 964 Bytes

prefer-toHaveBeenCalledWith.md

File metadata and controls

57 lines (47 loc) · 964 Bytes

Prefer toHaveBeenCalledWith

This rule recommends using toHaveBeenCalledWith instead of toHaveBeenCalled. Except for the usage with a negative matcher. not.toHaveBeenCalled() is a valid syntax according to the rule.

Rule details

This rule triggers a warning (is set to 1 by default).

The following pattern is a warning:

describe("", function() {
  it("", function() {
    f(1);
    expect(f).toHaveBeenCalled();
  });
});

The following patterns are not warnings:

describe("", function() {
  it("", function() {
    f(1);
    expect(f).toHaveBeenCalledWith(1);
  });
});
describe("", function() {
  it("", function() {
    f();
    expect(f).toHaveBeenCalledWith();
  });
});
describe("", function() {
  it("", function() {
    f(1);
    expect(f).not.toHaveBeenCalledWith(2);
  });
});
describe("", function() {
  it("", function() {
    expect(f).not.toHaveBeenCalled();
  });
});