Skip to content

linter: jest/no-standalone-expect ignores additionalTestBlockFunctions option #22390

@JasonKaz

Description

@JasonKaz

What version of Oxlint are you using?

1.64.0

What command did you run?

No response

What does your .oxlintrc.json (or oxlint.config.ts) config file look like?

{
  "plugins": ["jest"],
  "env": { "jest": true },
  "rules": {
    "jest/no-standalone-expect": [
      "deny",
      { "additionalTestBlockFunctions": ["beforeEach", "afterEach"] }
    ]
  }
}

What happened?

This situation is triggering a violation of the jest/no-standalone-expect rule:

/**
 * Minimal reproduction of oxlint bug: jest/no-standalone-expect ignores additionalTestBlockFunctions.
 *
 * ESLint with eslint-plugin-jest passes all of these because it respects:
 *   "jest/no-standalone-expect": ["error", { additionalTestBlockFunctions: ["beforeEach", "afterEach"] }]
 *
 * oxlint 1.64.0 flags every expect() inside beforeEach/afterEach regardless of that config option.
 * The option is accepted without error but silently ignored.
 *
 * Expected: 0 errors  (additionalTestBlockFunctions should whitelist beforeEach/afterEach)
 * Actual:   2 errors  (two expect() calls flagged as standalone)
 */

describe("additionalTestBlockFunctions reproduction", () => {
    // Case 1: expect inside beforeEach at the top level of a describe
    beforeEach(() => {
        expect(true).toBe(true); // <-- Flagged
    });

    describe("nested describe", () => {
        // Case 2: expect inside afterEach one level deep
        afterEach(() => {
            expect(true).toBe(true);  // <-- Flagged
        });
    });

    // Sanity check: expect inside it() should never be flagged
    it("should always pass", () => {
        expect(true).toBe(true);
    });
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions