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

"Duplicate test title" if running multiple tests on the same code (with different options) #18

Open
RebeccaStevens opened this issue Jan 4, 2021 · 2 comments

Comments

@RebeccaStevens
Copy link

RebeccaStevens commented Jan 4, 2021

The 3 tests in this example would all have the same name and thus cause an error when running ava.

import test from "ava";
import RuleTester from "eslint-ava-rule-tester";

import { name, rule } from "./path/to/rule";

const ruleTester = new RuleTester(test, { /* ... */ });

const filename = "file.ts";
const code = "// some code";

ruleTester.run(name, rule, {
  valid: [
    {
      filename,
      code,
      options: [{ flag1: true }],
    },
    {
      filename,
      code,
      options: [{ flag2: true }],
    }
  ],
  invalid: [
    {
      filename,
      code,
      options: [{ flag1: true, flag2: true }],
      errors: [
        // ...
      ],
    }
  ],
});
@RebeccaStevens
Copy link
Author

Workaround:

  • create a wrapper for ava's test function that ensures a unique name
const testNames = new Map();

function testWrapper(title: string, callback: Implementation<unknown>) {
  const count = (testNames.get(title) ?? 0) + 1;
  testNames.set(title, count);
  return test(`${title} - ${count}`, callback);
}
  • pass the wrapper function to the RuleTester
const ruleTester = new RuleTester(testWrapper, { /* ... */ });

@fisker
Copy link
Contributor

fisker commented Dec 19, 2023

Fixed by #27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants