File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
packages/jest-runtime/src Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3+ *
4+ * This source code is licensed under the MIT license found in the
5+ * LICENSE file in the root directory of this source tree.
6+ *
7+ */
8+
9+ 'use strict' ;
10+
11+ let createRuntime ;
12+
13+ describe ( 'Runtime' , ( ) => {
14+ beforeEach ( ( ) => {
15+ createRuntime = require ( 'createRuntime' ) ;
16+ } ) ;
17+
18+ describe ( 'resetModules' , ( ) => {
19+ it ( 'does not throw when accessing _isMockFunction on an unsafe global' , async ( ) => {
20+ const runtime = await createRuntime ( __filename ) ;
21+ runtime . _environment . global . UNSAFE_GLOBAL = new Proxy (
22+ { } ,
23+ {
24+ get ( target , p , receiver ) {
25+ if ( p === '_isMockFunction' ) throw new Error ( 'Unsafe global!' ) ;
26+ } ,
27+ } ,
28+ ) ;
29+ runtime . resetModules ( ) ;
30+ } ) ;
31+ } ) ;
32+ } ) ;
Original file line number Diff line number Diff line change @@ -1218,6 +1218,7 @@ export default class Runtime {
12181218 if (
12191219 ( ( typeof globalMock === 'object' && globalMock !== null ) ||
12201220 typeof globalMock === 'function' ) &&
1221+ '_isMockFunction' in globalMock &&
12211222 globalMock . _isMockFunction === true
12221223 ) {
12231224 globalMock . mockClear ( ) ;
You can’t perform that action at this time.
0 commit comments