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

What am I missing - mocking es6 imports #1736

Closed
oviava opened this issue Sep 19, 2016 · 2 comments
Closed

What am I missing - mocking es6 imports #1736

oviava opened this issue Sep 19, 2016 · 2 comments

Comments

@oviava
Copy link

oviava commented Sep 19, 2016

I'm using this in my module

import { myFirstFunction, mySecondFunction } from '../../MyModule';

When mocking in my test:

// THIS DOES NOT WORK
const mockFuncs = () => ({
    myFirstFunction: jest.fn(() => ({ type: 'TEST' })),
    mySecondFunction: jest.fn(() => ({ type: 'TEST' })),
});
jest.mock('../../MyModule', () => mockFuncs());

// ERR: mockFuncs is not a function
// THIS WORKS
function mockFuncs() {
  return {
    myFirstFunction: jest.fn(() => ({ type: 'TEST' })),
    mySecondFunction: jest.fn(() => ({ type: 'TEST' })),
  };
}

jest.mock('../../MyModule', () => mockFuncs());

I can't debug this as there seems to be an issue with debugger breakpoints in this version of jest.

@oviava
Copy link
Author

oviava commented Sep 19, 2016

figured it out, can close this, it's because of the hoisting.

@oviava oviava closed this as completed Sep 19, 2016
This was referenced Nov 17, 2020
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant