Skip to content

Commit 4efd7e2

Browse files
feat: config option to allow breaking changes (#1241)
1 parent 45302ea commit 4efd7e2

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

src/__tests__/config.test.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
import { getConfig, configure, resetToDefaults } from '../config';
1+
import {
2+
getConfig,
3+
configure,
4+
resetToDefaults,
5+
configureInternal,
6+
} from '../config';
27

38
beforeEach(() => {
49
resetToDefaults();
510
});
611

712
test('getConfig() returns existing configuration', () => {
13+
expect(getConfig().useBreakingChanges).toEqual(false);
814
expect(getConfig().asyncUtilTimeout).toEqual(1000);
915
expect(getConfig().defaultIncludeHiddenElements).toEqual(true);
1016
});
@@ -16,6 +22,7 @@ test('configure() overrides existing config values', () => {
1622
asyncUtilTimeout: 5000,
1723
defaultDebugOptions: { message: 'debug message' },
1824
defaultIncludeHiddenElements: true,
25+
useBreakingChanges: false,
1926
});
2027
});
2128

@@ -32,6 +39,16 @@ test('resetToDefaults() resets config to defaults', () => {
3239
expect(getConfig().defaultIncludeHiddenElements).toEqual(true);
3340
});
3441

42+
test('resetToDefaults() resets internal config to defaults', () => {
43+
configureInternal({
44+
useBreakingChanges: true,
45+
});
46+
expect(getConfig().useBreakingChanges).toEqual(true);
47+
48+
resetToDefaults();
49+
expect(getConfig().useBreakingChanges).toEqual(false);
50+
});
51+
3552
test('configure handles alias option defaultHidden', () => {
3653
expect(getConfig().defaultIncludeHiddenElements).toEqual(true);
3754

src/config.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { DebugOptions } from './helpers/debugDeep';
22

3+
/**
4+
* Global configuration options for React Native Testing Library.
5+
*/
36
export type Config = {
47
/** Default timeout, in ms, for `waitFor` and `findBy*` queries. */
58
asyncUtilTimeout: number;
@@ -16,13 +19,22 @@ export type ConfigAliasOptions = {
1619
defaultHidden: boolean;
1720
};
1821

19-
const defaultConfig: Config = {
22+
export type InternalConfig = Config & {
23+
/** Whether to use breaking changes intended for next major version release. */
24+
useBreakingChanges: boolean;
25+
};
26+
27+
const defaultConfig: InternalConfig = {
28+
useBreakingChanges: false,
2029
asyncUtilTimeout: 1000,
2130
defaultIncludeHiddenElements: true,
2231
};
2332

2433
let config = { ...defaultConfig };
2534

35+
/**
36+
* Configure global options for React Native Testing Library.
37+
*/
2638
export function configure(options: Partial<Config & ConfigAliasOptions>) {
2739
const { defaultHidden, ...restOptions } = options;
2840

@@ -38,6 +50,13 @@ export function configure(options: Partial<Config & ConfigAliasOptions>) {
3850
};
3951
}
4052

53+
export function configureInternal(option: Partial<InternalConfig>) {
54+
config = {
55+
...config,
56+
...option,
57+
};
58+
}
59+
4160
export function resetToDefaults() {
4261
config = { ...defaultConfig };
4362
}

0 commit comments

Comments
 (0)