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

[require-hook] Add option to allow class calls #1386

Open
marekdedic opened this issue Jun 26, 2023 · 2 comments
Open

[require-hook] Add option to allow class calls #1386

marekdedic opened this issue Jun 26, 2023 · 2 comments

Comments

@marekdedic
Copy link

Hi,
I have a lot of tests that are really similar, so I built a class that scaffolds all the tests and invoke it in my test file like so:

new NodeExtensionTester(new ExtensionToTest())
  .shouldMatchUnistNode({ type: "thematicBreak" })
  .shouldNotMatchUnistNode({ type: "horizontal_rule" })
  .shouldNotMatchUnistNode({ type: "other" })
  .runTests();

However, this triggers jest/require-hook. In that rule, there is the allowedFunctionCalls option. However, when I printed getNodeName(node) here, I got

NodeExtensionTester.shouldMatchUnistNode.shouldNotMatchUnistNode.shouldNotMatchUnistNode.runTests

... which is ugly and depends on all the methods called, so there's not really any point to using allowedFunctionCalls for this (instead of disable comments or disabling the rule altogether)

Could we add something like allowedClasses?

@G-Rath
Copy link
Collaborator

G-Rath commented Jun 30, 2023

Is there a reason why you're running this rule against your file if you have this custom extension? I'm not against adjusting the options to make the rule more flexible, but would like to understand more of your use-case first since I'm not sure why (or how) you'd want mix test cases with this (which is really when the result is needed - even if you're using things like jest.mock next to this, you can probably still safely disable require-hook)

@marekdedic
Copy link
Author

Yeah, I could disable this per-file in the config, that's true... I could also use disable comments. However, I expect to have more tests in more files that do not all use the class, so specifying which files to apply the rule to and which not would be a kind of pain...

Also you may want to use such a tester and then add some more tests manually in the same file, in which case you really have to use disable comments - I am not sure I'll be in such a scenario, but it's another option that comes to mind...

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

No branches or pull requests

2 participants