mirror of
https://github.com/callstack/react-native-testing-library.git
synced 2026-09-18 23:09:04 +08:00
55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
import type { DebugOptions } from './helpers/debug';
|
|
|
|
/**
|
|
* Global configuration options for React Native Testing Library.
|
|
*/
|
|
|
|
export type Config = {
|
|
/** Default timeout, in ms, for `waitFor` and `findBy*` queries. */
|
|
asyncUtilTimeout: number;
|
|
|
|
/** Default value for `includeHiddenElements` query option. */
|
|
defaultIncludeHiddenElements: boolean;
|
|
|
|
/** Default options for `debug` helper. */
|
|
defaultDebugOptions?: Partial<DebugOptions>;
|
|
};
|
|
|
|
export type ConfigAliasOptions = {
|
|
/** RTL-compatibility alias to `defaultIncludeHiddenElements` */
|
|
defaultHidden: boolean;
|
|
};
|
|
|
|
const defaultConfig: Config = {
|
|
asyncUtilTimeout: 1000,
|
|
defaultIncludeHiddenElements: false,
|
|
};
|
|
|
|
let config = { ...defaultConfig };
|
|
|
|
/**
|
|
* Configure global options for React Native Testing Library.
|
|
*/
|
|
export function configure(options: Partial<Config & ConfigAliasOptions>) {
|
|
const { defaultHidden, ...restOptions } = options;
|
|
|
|
const defaultIncludeHiddenElements =
|
|
restOptions.defaultIncludeHiddenElements ??
|
|
defaultHidden ??
|
|
config.defaultIncludeHiddenElements;
|
|
|
|
config = {
|
|
...config,
|
|
...restOptions,
|
|
defaultIncludeHiddenElements,
|
|
};
|
|
}
|
|
|
|
export function resetToDefaults() {
|
|
config = { ...defaultConfig };
|
|
}
|
|
|
|
export function getConfig() {
|
|
return config;
|
|
}
|