File tree 1 file changed +26
-0
lines changed
1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 1
1
import { render , screen } from '@testing-library/react' ;
2
2
import userEvent from '@testing-library/user-event' ;
3
+ import { act } from 'react-dom/test-utils' ;
3
4
4
5
import '@babel/polyfill' ;
5
6
@@ -109,4 +110,29 @@ describe('getStore', () => {
109
110
expect ( screen . getByTestId ( 'price' ) . textContent ) . toContain ( '0' ) ;
110
111
expect ( screen . getByTestId ( 'other' ) . textContent ) . toContain ( 'ARAL 10' ) ;
111
112
} ) ;
113
+
114
+ it ( 'should be possible to create methods to use the setter from getStore' , ( ) => {
115
+ const { useStore, getStore} = createStore ( { cart : { items : [ ] } } ) ;
116
+
117
+ function push ( proxy , value ) {
118
+ const [ val , set ] = proxy ( getStore ) ;
119
+ set ( [ ...val , value ] ) ;
120
+ }
121
+
122
+ function Cart ( ) {
123
+ const [ cart ] = useStore . cart ( ) ;
124
+ return < div data-testid = "items" > { cart . items . join ( ',' ) } </ div > ;
125
+ }
126
+
127
+ const items = ( proxy ) => proxy . cart . items ( ) ;
128
+
129
+ render ( < Cart /> ) ;
130
+
131
+ expect ( screen . getByTestId ( 'items' ) . textContent ) . toContain ( '' ) ;
132
+
133
+ act ( ( ) => push ( items , 'firstElement' ) ) ;
134
+ expect ( screen . getByTestId ( 'items' ) . textContent ) . toContain ( 'firstElement' ) ;
135
+ act ( ( ) => push ( items , 'secondElement' ) ) ;
136
+ expect ( screen . getByTestId ( 'items' ) . textContent ) . toContain ( 'firstElement,secondElement' ) ;
137
+ } )
112
138
} ) ;
You can’t perform that action at this time.
0 commit comments