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

__Rewire__ is not a function #235

Open
stoplion opened this issue Dec 10, 2020 · 1 comment
Open

__Rewire__ is not a function #235

stoplion opened this issue Dec 10, 2020 · 1 comment

Comments

@stoplion
Copy link

stoplion commented Dec 10, 2020

A file has a few exported functions...

export function foo() {}
export function bar() {}
export function baz() {}

In a test file...

import * as pathFileHelpers from 'path/to/file';

pathFileHelpers.__Rewire__({
   readFileSync: () => {
      return 'test test test'
    },
})

_get__(...).__Rewire__ is not a function

Why?

SO Question

@BenjaminVanRyseghem
Copy link

I got the same, but I figure out that if the exported function are "heavy" enough, it works.

By example

function bar() {
	return 42;
}

export function foo() {
	return 60;
}

This doesn't work, but

function bar() {
	return 42;
}

export function foo() {
	return bar();
}

does work.

Even trickier:

function baz() { return bar(); }

function bar() { return 42; }

export function foo() {
	return 60;
}

work as well, even though the added code is unused and unreachable. But it looks like having inner calls is mandatory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants