@@ -26,13 +26,13 @@ describe('useToast', () => {
26
26
close . mockClear ( ) ;
27
27
} ) ;
28
28
29
- let renderToastHook = ( toast , state , wrapper ) => {
30
- let { result} = renderHook ( ( ) => useToast ( { toast } , state , useRef ( document . createElement ( 'div' ) ) ) , { wrapper} ) ;
29
+ let renderToastHook = ( props , state , wrapper ) => {
30
+ let { result} = renderHook ( ( ) => useToast ( props , state , useRef ( document . createElement ( 'div' ) ) ) , { wrapper} ) ;
31
31
return result . current ;
32
32
} ;
33
33
34
34
it ( 'handles defaults' , function ( ) {
35
- let { closeButtonProps, toastProps, contentProps, titleProps} = renderToastHook ( { } , { close} ) ;
35
+ let { closeButtonProps, toastProps, contentProps, titleProps} = renderToastHook ( { toast : { } } , { close} ) ;
36
36
37
37
expect ( toastProps . role ) . toBe ( 'alertdialog' ) ;
38
38
expect ( contentProps . role ) . toBe ( 'alert' ) ;
@@ -42,12 +42,18 @@ describe('useToast', () => {
42
42
} ) ;
43
43
44
44
it ( 'handles close button' , function ( ) {
45
- let { closeButtonProps} = renderToastHook ( { key : 1 } , { close} ) ;
45
+ let { closeButtonProps} = renderToastHook ( { toast : { key : 1 } } , { close} ) ;
46
46
closeButtonProps . onPress ( ) ;
47
47
48
48
expect ( close ) . toHaveBeenCalledTimes ( 1 ) ;
49
49
expect ( close ) . toHaveBeenCalledWith ( 1 ) ;
50
50
} ) ;
51
+
52
+ it ( 'passes through data attributes' , function ( ) {
53
+ let { toastProps} = renderToastHook ( { toast : { } , 'data-test-id' : 'toast' } , { close} ) ;
54
+
55
+ expect ( toastProps [ 'data-test-id' ] ) . toBe ( 'toast' ) ;
56
+ } ) ;
51
57
} ) ;
52
58
53
59
describe ( 'single toast at a time' , ( ) => {
@@ -71,7 +77,7 @@ describe('single toast at a time', () => {
71
77
await user . tab ( ) ;
72
78
await user . keyboard ( '{Enter}' ) ;
73
79
await user . keyboard ( '{Enter}' ) ;
74
-
80
+
75
81
let toast = tree . getByRole ( 'alertdialog' ) ;
76
82
expect ( toast . textContent ) . toContain ( 'Mmmmm toast 2x' ) ;
77
83
let closeButton = within ( toast ) . getByRole ( 'button' ) ;
0 commit comments