File tree 2 files changed +47
-0
lines changed
packages/babel-plugin-jest-hoist/src
2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change 1
1
// Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
3
+ exports [` babel-plugin-jest-hoist automatic react runtime: automatic react runtime 1` ] = `
4
+
5
+ jest.mock('./App', () => () => <div >Hello world</div >);
6
+
7
+ ↓ ↓ ↓ ↓ ↓ ↓
8
+
9
+ _getJestObj().mock("./App", () => () =>
10
+ /*#__PURE__*/ _jsxDEV(
11
+ "div",
12
+ {
13
+ children : " Hello world"
14
+ } ,
15
+ void 0,
16
+ false,
17
+ {
18
+ fileName : _jsxFileName ,
19
+ lineNumber : 1 ,
20
+ columnNumber : 32
21
+ } ,
22
+ this
23
+ )
24
+ );
25
+
26
+ import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
27
+ var _jsxFileName = "";
28
+
29
+ function _getJestObj() {
30
+ const { jest } = require (" @jest/globals" );
31
+
32
+ _getJestObj = () => jest ;
33
+
34
+ return jest ;
35
+ }
36
+
37
+
38
+ ` ;
39
+
3
40
exports [` babel-plugin-jest-hoist top level mocking: top level mocking 1` ] = `
4
41
5
42
require('x');
Original file line number Diff line number Diff line change @@ -132,6 +132,16 @@ FUNCTIONS.mock = args => {
132
132
scope = scope . parent ;
133
133
}
134
134
135
+ if ( ! found ) {
136
+ const binding = scope . bindings [ name ] ;
137
+
138
+ // @ts -expect-error `init` does not exist
139
+ if ( binding ?. constant && scope . isPure ( binding . path . node . init , true ) ) {
140
+ // how to hoist???
141
+ found = true ;
142
+ }
143
+ }
144
+
135
145
if ( ! found ) {
136
146
const isAllowedIdentifier =
137
147
( scope . hasGlobal ( name ) && ALLOWED_IDENTIFIERS . has ( name ) ) ||
You can’t perform that action at this time.
0 commit comments