jest.mock curry function module
See original GitHub issueadd.js
export default a => b => a+b;
module.js
import add from './add';
export default {
add1: n => add(1)(n),
};
test/module.js
import add from '../add';
import module from '../module';
jest.mock('../add', () => () => jest.fn());
module.add1(6);
expect(add.mock.calls).toHaveLength(1);
this can be called, but add
wouldn’t be a mock function, instead add()
is a mock function, but the call params were not recorded correctly.
jest.mock('../add', () => () => jest.fn(a => b => a+b));
has also tried this, which doesn’t seem to work correctly as well.
jest.mock('../add', jest.fn(a => b => a+b));
this would throw the inline function
error
Is there a correct way to mock curry function at the moment?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
How to mock curry function with Jest?
So you mock add module with a function that return that when gets called it returns the spy, problem you can't test anything...
Read more >jest-mock-curry-fn
Start using jest-mock-curry-fn in your project by running `npm i jest-mock-curry-fn`. There are no other projects in the npm registry using ...
Read more >Mock Functions
Mock functions allow you to test the links between code by erasing the actual implementation of a function, capturing calls to the function...
Read more >Mock Functions · Jest
There are two ways to mock functions: Either by creating a mock function to use in test code, or writing a manual mock...
Read more >Implementing a curry function in JavaScript using TDD
Here we're going to implement a curry function in JavaScript. So in this case, the module or the unit is the function named...
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
don’t think mocking curry function is very straight-forward, had some snippets to stub one from a module:
Hey @zhenyulin! This issue tracker is not a help forum. I’m happy to help more using our discord channel or StackOverflow where there is an active jestjs tag for questions