diff --git a/packages/jest-config/src/__tests__/normalize.test.js b/packages/jest-config/src/__tests__/normalize.test.js index e1b9edf5c498..8d10cd35eb4a 100644 --- a/packages/jest-config/src/__tests__/normalize.test.js +++ b/packages/jest-config/src/__tests__/normalize.test.js @@ -827,7 +827,7 @@ describe('preset', () => { {}, ); - expect(options.moduleNameMapper).toEqual([['b', 'b'], ['a', 'a']]); + expect(options.moduleNameMapper).toEqual([['a', 'a'], ['b', 'b']]); expect(options.modulePathIgnorePatterns).toEqual(['b', 'a']); expect(options.setupFiles.sort()).toEqual([ '/node_modules/a', @@ -835,6 +835,32 @@ describe('preset', () => { '/node_modules/regenerator-runtime/runtime', ]); }); + + test('merges with options and moduleNameMapper preset is overridden by options', () => { + // Object initializer not used for properties as a workaround for + // sort-keys eslint rule while specifing properties in + // non-alphabetical order for a better test + const moduleNameMapper = {}; + moduleNameMapper.e = 'ee'; + moduleNameMapper.b = 'bb'; + moduleNameMapper.c = 'cc'; + moduleNameMapper.a = 'aa'; + const {options} = normalize( + { + moduleNameMapper, + preset: 'react-native', + rootDir: '/root/path/foo', + }, + {}, + ); + + expect(options.moduleNameMapper).toEqual([ + ['e', 'ee'], + ['b', 'bb'], + ['c', 'cc'], + ['a', 'aa'], + ]); + }); }); describe('preset without setupFiles', () => { diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index 2608c62f3fd5..852358bc35e0 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -76,6 +76,7 @@ const setupPreset = ( if (options.moduleNameMapper && preset.moduleNameMapper) { options.moduleNameMapper = Object.assign( {}, + options.moduleNameMapper, preset.moduleNameMapper, options.moduleNameMapper, );