File tree 2 files changed +38
-2
lines changed
2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change 1
- import { getConfig , configure , resetToDefaults } from '../config' ;
1
+ import {
2
+ getConfig ,
3
+ configure ,
4
+ resetToDefaults ,
5
+ configureInternal ,
6
+ } from '../config' ;
2
7
3
8
beforeEach ( ( ) => {
4
9
resetToDefaults ( ) ;
5
10
} ) ;
6
11
7
12
test ( 'getConfig() returns existing configuration' , ( ) => {
13
+ expect ( getConfig ( ) . useBreakingChanges ) . toEqual ( false ) ;
8
14
expect ( getConfig ( ) . asyncUtilTimeout ) . toEqual ( 1000 ) ;
9
15
expect ( getConfig ( ) . defaultIncludeHiddenElements ) . toEqual ( true ) ;
10
16
} ) ;
@@ -16,6 +22,7 @@ test('configure() overrides existing config values', () => {
16
22
asyncUtilTimeout : 5000 ,
17
23
defaultDebugOptions : { message : 'debug message' } ,
18
24
defaultIncludeHiddenElements : true ,
25
+ useBreakingChanges : false ,
19
26
} ) ;
20
27
} ) ;
21
28
@@ -32,6 +39,16 @@ test('resetToDefaults() resets config to defaults', () => {
32
39
expect ( getConfig ( ) . defaultIncludeHiddenElements ) . toEqual ( true ) ;
33
40
} ) ;
34
41
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
+
35
52
test ( 'configure handles alias option defaultHidden' , ( ) => {
36
53
expect ( getConfig ( ) . defaultIncludeHiddenElements ) . toEqual ( true ) ;
37
54
Original file line number Diff line number Diff line change 1
1
import { DebugOptions } from './helpers/debugDeep' ;
2
2
3
+ /**
4
+ * Global configuration options for React Native Testing Library.
5
+ */
3
6
export type Config = {
4
7
/** Default timeout, in ms, for `waitFor` and `findBy*` queries. */
5
8
asyncUtilTimeout : number ;
@@ -16,13 +19,22 @@ export type ConfigAliasOptions = {
16
19
defaultHidden : boolean ;
17
20
} ;
18
21
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 ,
20
29
asyncUtilTimeout : 1000 ,
21
30
defaultIncludeHiddenElements : true ,
22
31
} ;
23
32
24
33
let config = { ...defaultConfig } ;
25
34
35
+ /**
36
+ * Configure global options for React Native Testing Library.
37
+ */
26
38
export function configure ( options : Partial < Config & ConfigAliasOptions > ) {
27
39
const { defaultHidden, ...restOptions } = options ;
28
40
@@ -38,6 +50,13 @@ export function configure(options: Partial<Config & ConfigAliasOptions>) {
38
50
} ;
39
51
}
40
52
53
+ export function configureInternal ( option : Partial < InternalConfig > ) {
54
+ config = {
55
+ ...config ,
56
+ ...option ,
57
+ } ;
58
+ }
59
+
41
60
export function resetToDefaults ( ) {
42
61
config = { ...defaultConfig } ;
43
62
}
You can’t perform that action at this time.
0 commit comments