Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test.if should be evaluated after beforeAll lifecycle #18062

Closed
KilianB opened this issue Mar 11, 2025 · 1 comment
Closed

test.if should be evaluated after beforeAll lifecycle #18062

KilianB opened this issue Mar 11, 2025 · 1 comment
Labels
bug Something isn't working needs triage

Comments

@KilianB
Copy link
Contributor

KilianB commented Mar 11, 2025

What version of Bun is running?

1.2.6-canary.3+a79f92df9

What platform is your computer?

No response

What steps can reproduce the bug?

I would expect the following test suite to correctly pass, but the last test case fails as it isn't skipped.
test.skipIf evaluates the conditions before the beforeAll method ran which might be correct by design, but my expectation is to set up my test conditions inside the beforeAll method.

It is inconsistent that a test should be skipped based on a condition, but inside the test function this condition might be true.

describe("Skip Test", () => {
  const scopedVar = ["a"];

  beforeAll(() => {
    scopedVar.push("injected");
  });

  test.skipIf(scopedVar.includes("a"))(
    "Should be skipped based on scopedVar",
    () => {
      expect().fail();
    }
  );

  test.skipIf(scopedVar.includes("b"))(
    "Should not be skipped based on scopedVar",
    () => {
      expect().pass();
    }
  );

  test.skipIf(scopedVar.includes("injected"))(
    "Should be skipped based on beforeAll",
    () => {
      //Evaluation here shows that scopedVar actually includes "injected"
      console.log(scopedVar);
      expect().fail();
    }
  );
});

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

@KilianB KilianB added bug Something isn't working needs triage labels Mar 11, 2025
@DonIsaac
Copy link
Contributor

Unfortunately, test.skipIf does not receive a "function call" as a parameter- the call to scopedVar.includes(...) evaluates when the describe block runs, then the return value gets passed. This is not a bug in Bun; this is how pass-by-value works.

@DonIsaac DonIsaac closed this as not planned Won't fix, can't repro, duplicate, stale Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

2 participants