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.

jest.mock curry function module

See original GitHub issue

add.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:closed
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
zhenyulincommented, Jan 4, 2019

don’t think mocking curry function is very straight-forward, had some snippets to stub one from a module:

jest.mock('module', () => ({
	tagService: () => inputFunction => inputFunction,  // doesn't seem curry can be mocked nicely
	metricsAction: jest.fn(inputFunction => inputFunction),
}));
1reaction
rickhanloniicommented, Feb 21, 2018

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

Read more comments on GitHub >

github_iconTop 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 >

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