Skip to content

Commit

Permalink
hack a "fix"
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Oct 31, 2020
1 parent acb43e5 commit 3950686
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
@@ -1,5 +1,42 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`babel-plugin-jest-hoist automatic react runtime: automatic react runtime 1`] = `
jest.mock('./App', () => () => <div>Hello world</div>);
↓ ↓ ↓ ↓ ↓ ↓
_getJestObj().mock("./App", () => () =>
/*#__PURE__*/ _jsxDEV(
"div",
{
children: "Hello world"
},
void 0,
false,
{
fileName: _jsxFileName,
lineNumber: 1,
columnNumber: 32
},
this
)
);
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
var _jsxFileName = "";
function _getJestObj() {
const { jest } = require("@jest/globals");
_getJestObj = () => jest;
return jest;
}
`;

exports[`babel-plugin-jest-hoist top level mocking: top level mocking 1`] = `
require('x');
Expand Down
10 changes: 10 additions & 0 deletions packages/babel-plugin-jest-hoist/src/index.ts
Expand Up @@ -132,6 +132,16 @@ FUNCTIONS.mock = args => {
scope = scope.parent;
}

if (!found) {
const binding = scope.bindings[name];

// @ts-expect-error `init` does not exist
if (binding?.constant && scope.isPure(binding.path.node.init, true)) {
// how to hoist???
found = true;
}
}

if (!found) {
const isAllowedIdentifier =
(scope.hasGlobal(name) && ALLOWED_IDENTIFIERS.has(name)) ||
Expand Down

0 comments on commit 3950686

Please sign in to comment.