diff --git a/packages/jest-resolve/src/__tests__/resolve.test.ts b/packages/jest-resolve/src/__tests__/resolve.test.ts index 35893cf512ab..4d8d174385a7 100644 --- a/packages/jest-resolve/src/__tests__/resolve.test.ts +++ b/packages/jest-resolve/src/__tests__/resolve.test.ts @@ -162,11 +162,13 @@ describe('resolveModule', () => { extensions: ['.js'], } as ResolverConfig); const mocksDirectory = path.resolve(__dirname, '../__mocks__'); - const resolved = resolver.resolveModule( - path.join(mocksDirectory, 'foo/foo.js'), - './', - ); - expect(resolved).toBe(path.join(mocksDirectory, 'foo/index.js')); + const fooSlashFoo = path.join(mocksDirectory, 'foo/foo.js'); + const fooSlashIndex = path.join(mocksDirectory, 'foo/index.js'); + + const resolvedWithSlash = resolver.resolveModule(fooSlashFoo, './'); + const resolvedWithDot = resolver.resolveModule(fooSlashFoo, '.'); + expect(resolvedWithSlash).toBe(fooSlashIndex); + expect(resolvedWithSlash).toBe(resolvedWithDot); }); }); diff --git a/packages/jest-resolve/src/defaultResolver.ts b/packages/jest-resolve/src/defaultResolver.ts index c9992b6882d0..40ded2c1f506 100644 --- a/packages/jest-resolve/src/defaultResolver.ts +++ b/packages/jest-resolve/src/defaultResolver.ts @@ -61,7 +61,7 @@ function resolveSync( if (REGEX_RELATIVE_IMPORT.test(target)) { // resolve relative import let resolveTarget = path.resolve(basedir, target); - if (target === '..' || target.endsWith('/')) { + if (target === '.' || target === '..' || target.endsWith('/')) { resolveTarget += '/'; } const result = tryResolve(resolveTarget);