diff --git a/src/__tests__/config.test.ts b/src/__tests__/config.test.ts index 599e36da7..c197b9c3a 100644 --- a/src/__tests__/config.test.ts +++ b/src/__tests__/config.test.ts @@ -1,10 +1,16 @@ -import { getConfig, configure, resetToDefaults } from '../config'; +import { + getConfig, + configure, + resetToDefaults, + configureInternal, +} from '../config'; beforeEach(() => { resetToDefaults(); }); test('getConfig() returns existing configuration', () => { + expect(getConfig().useBreakingChanges).toEqual(false); expect(getConfig().asyncUtilTimeout).toEqual(1000); expect(getConfig().defaultIncludeHiddenElements).toEqual(true); }); @@ -16,6 +22,7 @@ test('configure() overrides existing config values', () => { asyncUtilTimeout: 5000, defaultDebugOptions: { message: 'debug message' }, defaultIncludeHiddenElements: true, + useBreakingChanges: false, }); }); @@ -32,6 +39,16 @@ test('resetToDefaults() resets config to defaults', () => { expect(getConfig().defaultIncludeHiddenElements).toEqual(true); }); +test('resetToDefaults() resets internal config to defaults', () => { + configureInternal({ + useBreakingChanges: true, + }); + expect(getConfig().useBreakingChanges).toEqual(true); + + resetToDefaults(); + expect(getConfig().useBreakingChanges).toEqual(false); +}); + test('configure handles alias option defaultHidden', () => { expect(getConfig().defaultIncludeHiddenElements).toEqual(true); diff --git a/src/config.ts b/src/config.ts index 0f3a8c22f..64de13d13 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,5 +1,8 @@ import { DebugOptions } from './helpers/debugDeep'; +/** + * Global configuration options for React Native Testing Library. + */ export type Config = { /** Default timeout, in ms, for `waitFor` and `findBy*` queries. */ asyncUtilTimeout: number; @@ -16,13 +19,22 @@ export type ConfigAliasOptions = { defaultHidden: boolean; }; -const defaultConfig: Config = { +export type InternalConfig = Config & { + /** Whether to use breaking changes intended for next major version release. */ + useBreakingChanges: boolean; +}; + +const defaultConfig: InternalConfig = { + useBreakingChanges: false, asyncUtilTimeout: 1000, defaultIncludeHiddenElements: true, }; let config = { ...defaultConfig }; +/** + * Configure global options for React Native Testing Library. + */ export function configure(options: Partial) { const { defaultHidden, ...restOptions } = options; @@ -38,6 +50,13 @@ export function configure(options: Partial) { }; } +export function configureInternal(option: Partial) { + config = { + ...config, + ...option, + }; +} + export function resetToDefaults() { config = { ...defaultConfig }; }