1

Is there a better way to mock modules with jest and ESM?

It starts with the title as being opinion-based. Then there is a question

is there a better way to avoid that syntax above every time I need to mock/spy a module function?

To me, this is also opinion-based. And it probably belongs on Code Review.

7
  • 1
    "Is there a better way" certainly, at best, is too broad. "Better" doesn't have a definition and what is "better" is subjective; less code, faster compile time, faster run time, easier to read for a "new" developer, doesn't use additional libraries, etc, etc. The second question, "Is there a way to let VSCode using the dynamic imports everywhere (in the tests folder, for the .spec. files)?", however, does appear to be more on topic. Perhaps what the question actually needs is a little bit of an edit.
    – Thom A
    Mar 22 at 11:54
  • 3
    This post probably got so many upvotes because a lot of people were experiencing the same issue, not necessarily because it was a good question. IMO posts like these shouldn't be audits because they're failed mostly due to genuine disagreement rather than negligence. Compared to LQA and SE queue audits, there is too much of a gray area between a good post and a bad post.
    – Michael M.
    Mar 22 at 12:06
  • 1
  • @MichaelM. - I would say that is a good indication that it shouldn't be an audit question. Mar 22 at 12:13
  • 1
    @ThomA - I agree that it could do with an edit, but it did not get an edit, so I would say it's not a suitable question for audit. Mar 22 at 12:13
  • 1
    In the case of "known good" audits like this one, you can remove it from the review queue yourself by downvoting and/or voting to close. Mar 22 at 13:05
  • 2
    "status-complete" - there are now 2 down votes on the question along with being closed as opinion-voted. As result it will not show up as known-good audit. Mar 22 at 16:47

0

You must log in to answer this question.

Browse other questions tagged .