@@ -29,7 +29,7 @@ describe('<CurrencyInput/> onBlur', () => {
29
29
userEvent . type ( screen . getByRole ( 'textbox' ) , '123' ) ;
30
30
fireEvent . focusOut ( screen . getByRole ( 'textbox' ) ) ;
31
31
32
- expect ( onBlurSpy ) . toBeCalled ( ) ;
32
+ expect ( onBlurSpy ) . toHaveBeenCalled ( ) ;
33
33
34
34
expect ( onValueChangeSpy ) . toHaveBeenLastCalledWith ( '123.00' , name , {
35
35
float : 123 ,
@@ -40,13 +40,34 @@ describe('<CurrencyInput/> onBlur', () => {
40
40
expect ( screen . getByRole ( 'textbox' ) ) . toHaveValue ( '$123.00' ) ;
41
41
} ) ;
42
42
43
+ it ( 'should call onBlur, but not onValueChange' , ( ) => {
44
+ render (
45
+ < CurrencyInput
46
+ name = { name }
47
+ prefix = "$"
48
+ onBlur = { onBlurSpy }
49
+ onValueChange = { onValueChangeSpy }
50
+ formatValueOnBlur = { false }
51
+ decimalScale = { 2 }
52
+ />
53
+ ) ;
54
+
55
+ userEvent . type ( screen . getByRole ( 'textbox' ) , '123' ) ;
56
+ fireEvent . focusOut ( screen . getByRole ( 'textbox' ) ) ;
57
+
58
+ expect ( onBlurSpy ) . toHaveBeenCalled ( ) ;
59
+
60
+ expect ( onValueChangeSpy ) . toHaveBeenCalledTimes ( 3 ) ;
61
+ expect ( screen . getByRole ( 'textbox' ) ) . toHaveValue ( '$123.00' ) ;
62
+ } ) ;
63
+
43
64
it ( 'should call onBlur for 0' , ( ) => {
44
65
render ( < CurrencyInput name = { name } prefix = "$" onBlur = { onBlurSpy } /> ) ;
45
66
46
67
userEvent . type ( screen . getByRole ( 'textbox' ) , '0' ) ;
47
68
fireEvent . focusOut ( screen . getByRole ( 'textbox' ) ) ;
48
69
49
- expect ( onBlurSpy ) . toBeCalled ( ) ;
70
+ expect ( onBlurSpy ) . toHaveBeenCalled ( ) ;
50
71
51
72
expect ( screen . getByRole ( 'textbox' ) ) . toHaveValue ( '$0' ) ;
52
73
} ) ;
@@ -56,7 +77,7 @@ describe('<CurrencyInput/> onBlur', () => {
56
77
57
78
fireEvent . focusOut ( screen . getByRole ( 'textbox' ) ) ;
58
79
59
- expect ( onBlurSpy ) . toBeCalled ( ) ;
80
+ expect ( onBlurSpy ) . toHaveBeenCalled ( ) ;
60
81
61
82
expect ( screen . getByRole ( 'textbox' ) ) . toHaveValue ( '' ) ;
62
83
} ) ;
@@ -67,7 +88,7 @@ describe('<CurrencyInput/> onBlur', () => {
67
88
userEvent . type ( screen . getByRole ( 'textbox' ) , '-' ) ;
68
89
fireEvent . focusOut ( screen . getByRole ( 'textbox' ) ) ;
69
90
70
- expect ( onBlurSpy ) . toBeCalled ( ) ;
91
+ expect ( onBlurSpy ) . toHaveBeenCalled ( ) ;
71
92
72
93
expect ( screen . getByRole ( 'textbox' ) ) . toHaveValue ( '' ) ;
73
94
} ) ;
0 commit comments