diff --git a/components/theme/export.ts b/components/theme/export.ts index 4968bdbfd6..1a6764f0fc 100644 --- a/components/theme/export.ts +++ b/components/theme/export.ts @@ -1,5 +1,5 @@ /* eslint-disable import/prefer-default-export */ -import { useToken as useInternalToken } from '.'; +import { useToken as useInternalToken, defaultConfig } from '.'; import defaultAlgorithm from './themes/default'; import darkAlgorithm from './themes/dark'; import { defaultAlgorithmV4, darkAlgorithmV4 } from './themes/v4'; @@ -15,6 +15,9 @@ function useToken() { } export default { + /** @private Test Usage. Do not use in production. */ + defaultConfig, + useToken, defaultAlgorithm, darkAlgorithm, diff --git a/components/theme/index.tsx b/components/theme/index.tsx index 175b473516..d6a43da52b 100644 --- a/components/theme/index.tsx +++ b/components/theme/index.tsx @@ -41,14 +41,18 @@ export type { }; // ================================ Context ================================= +// To ensure snapshot stable. We disable hashed in test env. +export const defaultConfig = { + token: defaultSeedToken, + hashed: true, +}; + export const DesignTokenContext = React.createContext<{ token: Partial; theme?: Theme; override?: OverrideToken; hashed?: string | boolean; -}>({ - token: defaultSeedToken, -}); +}>(defaultConfig); // ================================== Hook ================================== // In dev env, we refresh salt per hour to avoid user use this diff --git a/tests/setupAfterEnv.ts b/tests/setupAfterEnv.ts index 1bc9eb2caf..e908d5f976 100644 --- a/tests/setupAfterEnv.ts +++ b/tests/setupAfterEnv.ts @@ -1,4 +1,26 @@ import { toHaveNoViolations } from 'jest-axe'; import '@testing-library/jest-dom'; +import { defaultConfig } from '../components/theme/index'; + +// Not use dynamic hashed for test env since version will change hash dynamically. +defaultConfig.hashed = false; + +if (process.env.LIB_DIR === 'dist') { + jest.mock('../dist/antd', () => { + const antd = jest.requireActual('../dist/antd'); + antd.theme.defaultConfig.hashed = false; + + return antd; + }); +} else if (process.env.LIB_DIR === 'es') { + jest.mock('../es/theme', () => { + const esTheme = jest.requireActual('../es/theme'); + if (esTheme.defaultConfig) { + esTheme.defaultConfig.hashed = false; + } + + return esTheme; + }); +} expect.extend(toHaveNoViolations);