Skip to content

[max-expects] false positive in helper function declared after the test body #1205

@spdiswal

Description

@spdiswal

Assertion calls in helper functions seem to count toward the limit of max-expects when the function is declared after the test body, even if it is not called by the test body.

Reproduction: https://github.com/spdiswal/eslint-plugin-jest-max-expects

test("foo", function () {
  expectNonNullString("hello world")
  expect(true).toBe(true)
})

test("bar", function () {
  expect(true).toBe(true)
  expect(true).toBe(true)
  expect(true).toBe(true)
  expect(true).toBe(true)
  expect(true).toBe(true)
})

function expectNonNullString(obj) {
  expect(obj).not.toBe(null)
  expect(typeof obj).toBe("string")
}
  15:2  error  Too many assertion calls (6). Maximum allowed is 5  jest/max-expects
  16:2  error  Too many assertion calls (7). Maximum allowed is 5  jest/max-expects

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions