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

Ideas for mocking #78

Closed
IanVS opened this issue Sep 29, 2022 · 1 comment
Closed

Ideas for mocking #78

IanVS opened this issue Sep 29, 2022 · 1 comment

Comments

@IanVS
Copy link
Contributor

IanVS commented Sep 29, 2022

Hi, I'm attempting to convert from globby to fdir, and I'm curious if you have any ideas for a good way to mock fdir returns. Previously, we had:

(globby.sync as jest.Mock).mockReturnValueOnce([]);

But, since fdir uses a fluent api, I can't just mock fdir.sync. Is this something you've run into before? And if so, how did you handle it?

@IanVS
Copy link
Contributor Author

IanVS commented Sep 29, 2022

I think I figured out something that works:

const syncMock = jest.fn();
const crawlerMock = jest.fn().mockImplementation(() => {
  return {
    sync: syncMock,
  };
});
jest.spyOn(fdir.prototype, 'crawl').mockImplementation(crawlerMock);

Happy to hear any other suggestions, but this seems to get me what I want.

@IanVS IanVS closed this as completed Sep 29, 2022
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

1 participant