question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`prefer-spy-on` should ignore `jest.fn` outside of `test` blocks

See original GitHub issue

Per this, the new rule should not recommend replacing jest.fn with jest.spyOn when used outside of test blocks, since jest.spyOn can’t even be used outside of test blocks.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
garykingcommented, Aug 5, 2019

Yeah I decided to use files: ['**/__mocks__/*.js'],.

0reactions
G-Rathcommented, Aug 5, 2019

You can use multiple patterns yes, but you should also be able to cover it w/ a single glob pattern, which I thought mine should do…

You might need ** instead of * - my globbing isn’t super strong; it otherwise could just be b/c of the paths being used you have to account for /*/__mocks__/ somehow (if that makes sense).

Eitherway, using multiple patterns will definitely cover it 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Jest Object
The jest object is automatically in scope within every test file. The methods in the jest object help create mocks and let you...
Read more >
Mock Functions or Spies Demystified - How Does jest.fn() Work?
In this guide, we will focus on the jest.fn method, the simplest way to create a mock function. This method can receive an...
Read more >
eslint-plugin-jest - npm
Start using eslint-plugin-jest in your project by running `npm i ... Disallow using expect outside of it or test blocks, ✓.
Read more >
How to limit the scope of Jest mocked functions to a single test
This is how I structure my tests: Having a beforeAll block in the beginning of the test suit for. setting up the mocks;...
Read more >
How to automatically reset mocks and restore spies in Jest
As it seemed, it turned out Jest can be configured to do an automatic reset / restore before executing each unit test spec....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found