File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ <script >
2+ import {getContext } from ' svelte' ;
3+ import {key } from ' ./key' ;
4+
5+ export let name;
6+
7+ const {form , handleChange } = getContext (key);
8+ </script >
9+
10+ <textarea {name } on:change ={handleChange } on:blur ={handleChange } {...$$props }>
11+ {$form [name ]}
12+ </textarea >
Original file line number Diff line number Diff line change 11export { createForm } from './create-form' ;
22export { default as Form } from './components/Form.svelte' ;
3+ export { default as Textarea } from './components/Textarea.svelte' ;
34export { default as Field } from './components/Field.svelte' ;
45export { default as Select } from './components/Select.svelte' ;
56export { default as ErrorMessage } from './components/ErrorMessage.svelte' ;
Original file line number Diff line number Diff line change 1+ import { render as renderTl , fireEvent , waitFor } from '@testing-library/svelte' ;
2+
3+ import Form from '../lib/components/Form.svelte' ;
4+ import Textarea from '../lib/components/Textarea.svelte' ;
5+
6+ const defaultProps = {
7+ initialValues : {
8+ description : '' ,
9+ } ,
10+ [ 'onSubmit' ] : ( ) => { } ,
11+ } ;
12+
13+ const render = ( ui , props = defaultProps ) => {
14+ return renderTl ( < Form { ...props } > { ui } </ Form > , { props} ) ;
15+ } ;
16+
17+ describe ( 'Textarea' , ( ) => {
18+ test ( '-> updates value on change' , async ( ) => {
19+ const label = 'description' ;
20+ const props = { ...defaultProps } ;
21+ const { getByLabelText} = render (
22+ < >
23+ < label for = { label } > { label } </ label >
24+ < Textarea id = { label } name = { label } />
25+ </ > ,
26+ props ,
27+ ) ;
28+
29+ const textarea = getByLabelText ( label ) ;
30+ expect ( textarea . value . trim ( ) ) . toBe ( props . initialValues . description ) ;
31+
32+ const value = 'foo' ;
33+
34+ await fireEvent . change ( textarea , { target : { value} } ) ;
35+
36+ expect ( textarea . value ) . toContain ( value ) ;
37+ } ) ;
38+ } ) ;
You can’t perform that action at this time.
0 commit comments