Why manual mock by creating manual mock file in __mocks__ folder not work
See original GitHub issueI tried mock method in ES6 class, by creating manual mock file in __mock__
folder, but mock file not working at all. Here is my project:
├── __mocks__
│ └── MockTestDependency.js
├── MockTestDependency.js
└── MockTest.test.js
// ./MockTestDependency.js
export default class MockTestDependency {
addAction(value1, value2) {
return value1 + value2
}
}
// ./__mocks__/MockTestDependency.js
export default {
addAction: jest.fn((value1, value2) => {
return value1 + value2 + 1
})
}
// ./MockTest.test.js
import MockTestDependency from "./MockTestDependency"
beforeAll(() => {
jest.mock('MockTestDependency')
})
describe('mock test', () => {
it('first case', () => {
let mockTestDependency = new MockTestDependency()
expect(mockTestDependency.addAction(1, 2)).toBe(4)
})
})
Any help would be appreciated.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7
Top Results From Across the Web
Manual mocking using __mocks__ not working - Stack Overflow
I went through jest documentation for manual mocking and tried creating mocks folder as instructed. Please find the folder structure below.
Read more >Manual Mocks - Jest
Manual mocks are used to stub out functionality with mock data. For example, instead of accessing a remote resource like a website or...
Read more >Mock defined in __mocks__ directory not being ... - GitHub
I have a file named app.js. Immediately adjacent to that I have a manual __mocks__/app.js file. I have a test that both requires...
Read more >Manual Mocks - Jest - w3resource
When a given module has a manual mock, Jest's module system uses that module when explicitly calling jest.mock('moduleName'). However, when you ...
Read more >How To Do Manual Mock In Jest Unit Testing | by Kris Ma
A much powerful but uncommon way of mocking service in jest unit test ... Jest has two ways to mock functions: Either by...
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
still cannot repro
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.