diff --git a/packages/jest-config/src/ValidConfig.ts b/packages/jest-config/src/ValidConfig.ts index d8d4ff8bcb5f..db7ea5fe6d3c 100644 --- a/packages/jest-config/src/ValidConfig.ts +++ b/packages/jest-config/src/ValidConfig.ts @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. */ +import type {SnapshotFormat} from '@jest/schemas'; import type {Config} from '@jest/types'; import {replacePathSepForRegex} from 'jest-regex-util'; import {multipleValidOptions} from 'jest-validate'; @@ -110,7 +111,10 @@ const initialOptions: Config.InitialOptions = { skipFilter: false, skipNodeResolution: false, slowTestThreshold: 5, - snapshotFormat: PRETTY_FORMAT_DEFAULTS, + snapshotFormat: { + ...PRETTY_FORMAT_DEFAULTS, + compareKeys: () => {}, + } as SnapshotFormat, snapshotResolver: '/snapshotResolver.js', snapshotSerializers: ['my-serializer-module'], testEnvironment: 'jest-environment-node', diff --git a/packages/jest-config/src/__tests__/normalize.test.ts b/packages/jest-config/src/__tests__/normalize.test.ts index 6b5732afa047..fb229b4e335d 100644 --- a/packages/jest-config/src/__tests__/normalize.test.ts +++ b/packages/jest-config/src/__tests__/normalize.test.ts @@ -9,6 +9,7 @@ import {createHash} from 'crypto'; import path from 'path'; import semver = require('semver'); +import type {SnapshotFormat} from '@jest/schemas'; import type {Config} from '@jest/types'; import {escapeStrForRegex} from 'jest-regex-util'; import Defaults from '../Defaults'; @@ -1918,3 +1919,20 @@ describe('updateSnapshot', () => { Defaults.ci = defaultCiConfig; }); }); + +describe('snapshotFormat', () => { + it('should accept custom `compareKeys`', async () => { + const compareKeys = () => 0; + + const {options} = await normalize( + { + ci: false, + rootDir: '/root/', + snapshotFormat: {compareKeys} as SnapshotFormat, + }, + {} as Config.Argv, + ); + + expect((options.snapshotFormat as any).compareKeys).toBe(compareKeys); + }); +});