jest.mock() does not work with using backticks e.g. jest.mock(`fs`)
See original GitHub issueDo you want to request a feature or report a bug? Bug
What is the current behavior?
// Works
jest.mock('fs');
// Doesn't work (backticks instead of single or double quotes)
jest.mock(`fs`);
If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install
and yarn test
.
It is not possible to reproduce this on repl.it, but it is pretty simple to test.
- Create a
__mocks__
directory with a mock forfs
- Create a test which
jest.mock(`fs`)
s using backticks fs
is not mocked
What is the expected behavior?
It should mock fs
no matter if single or double quotes or backticks are used.
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
Jest: 22.1.4 Node: v8.7.0 npm: 5.6.0
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Mock fs function with jest - node.js - Stack Overflow
The error there is because it is looking for a method called fs.mkdirSync on your logger object, which doesn't exist.
Read more >jest-mock | Yarn - Package Manager
Creates a new module mocker that generates mocks as if they were created in an environment with the given global object.
Read more >Mock Functions - Jest
Accepts a string to use in test result output in place of 'jest.fn()' to indicate which mock function is being referenced. For example:...
Read more >Unit Testing in Typescript/NodeJS - PhalanxHead
Jest is a test and mocking framework built in and for NodeJS. Typescript compatibility has been built over the top of it, but...
Read more >How to Write Unit Tests for Asynchronous Redux Thunks in ...
So I'm using the older require() syntax, which confers an any type and then we coerce to type jest.Mock . And then the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
#5426
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.