Skip to content

Commit a818709

Browse files
SimenBIanVS
authored andcommitted
fix mock
# Conflicts: # packages/jest-resolve/src/defaultResolver.ts
1 parent 38588b1 commit a818709

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

packages/jest-resolve/src/__tests__/resolve.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ jest.mock('../__mocks__/userResolverAsync');
2424
// in very strange ways. Instead just spy on it and its `sync` method.
2525
jest.mock('resolve', () => {
2626
const originalModule = jest.requireActual('resolve');
27-
return {
28-
...originalModule,
29-
sync: jest.spyOn(originalModule, 'sync'),
30-
};
27+
28+
const m = jest.fn((...args) => originalModule(...args));
29+
Object.assign(m, originalModule);
30+
m.sync = jest.spyOn(originalModule, 'sync');
31+
32+
return m;
3133
});
3234

3335
const mockResolveSync = <

packages/jest-resolve/src/defaultResolver.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
import * as fs from 'graceful-fs';
99
import pnpResolver from 'jest-pnp-resolver';
1010
import resolveAsync = require('resolve');
11-
import type {AsyncOpts, Opts as ResolveOpts, SyncOpts} from 'resolve';
1211
import type {Config} from '@jest/types';
1312
import {tryRealpath} from 'jest-util';
13+
1414
const resolveSync = resolveAsync.sync;
1515

16-
export interface ResolverOptions extends ResolveOpts {
16+
export interface ResolverOptions extends resolveAsync.Opts {
1717
basedir: Config.Path;
1818
browser?: boolean;
1919
conditions?: Array<string>;
@@ -80,7 +80,9 @@ export async function defaultResolverAsync(
8080
/**
8181
* getSyncResolveOptions returns resolution options that are used synchronously.
8282
*/
83-
function getSyncResolveOptions(options: ResolverOptions): SyncOpts {
83+
function getSyncResolveOptions(
84+
options: ResolverOptions,
85+
): resolveAsync.SyncOpts {
8486
return {
8587
...options,
8688
isDirectory: isDirectorySync,
@@ -94,7 +96,9 @@ function getSyncResolveOptions(options: ResolverOptions): SyncOpts {
9496
/**
9597
* getAsyncResolveOptions returns resolution options that are used asynchronously.
9698
*/
97-
function getAsyncResolveOptions(options: ResolverOptionsAsync): AsyncOpts {
99+
function getAsyncResolveOptions(
100+
options: ResolverOptionsAsync,
101+
): resolveAsync.AsyncOpts {
98102
return {
99103
...options,
100104
isDirectory: isDirectoryAsync,

0 commit comments

Comments
 (0)