@@ -810,9 +810,9 @@ describe('LiveController data-model Tests', () => {
810
810
<div ${ initComponent ( data ) } >
811
811
<form data-model>
812
812
<textarea name="comment" data-testid="comment">${ data . comment } </textarea>
813
- </form>
813
+ </form>
814
814
815
- <button data-action="live#$render">Reload</button >
815
+ <input data-testid="other-input" >
816
816
</div>
817
817
` ) ;
818
818
@@ -823,17 +823,18 @@ describe('LiveController data-model Tests', () => {
823
823
// delay slightly so we can type in the textarea
824
824
. delayResponse ( 10 ) ;
825
825
826
- getByText ( test . element , 'Reload' ) . click ( ) ;
826
+ const renderPromise = test . component . render ( ) ;
827
827
// mimic changing the field, but without (yet) triggering the change event
828
828
const commentField = getByTestId ( test . element , 'comment' ) ;
829
- if ( ! ( commentField instanceof HTMLTextAreaElement ) ) {
830
- throw new Error ( 'wrong type' ) ;
831
- }
829
+ const inputField = getByTestId ( test . element , 'other-input' ) ;
832
830
userEvent . type ( commentField , ' ftw!' ) ;
831
+ // To make the test more robust, make the textarea NOT the active element.
832
+ // The active element's value is ignored during morphing. Here, we want
833
+ // to test that even if the morph system *does* want to update the value
834
+ // of the textarea, the value will be kept.
835
+ userEvent . type ( inputField , 'making this element active' ) ;
833
836
834
- // wait for loading start and end
835
- await waitFor ( ( ) => expect ( test . element ) . toHaveAttribute ( 'busy' ) ) ;
836
- await waitFor ( ( ) => expect ( test . element ) . not . toHaveAttribute ( 'busy' ) ) ;
837
+ await renderPromise ;
837
838
838
839
expect ( commentField ) . toHaveValue ( 'Live components ftw!' ) ;
839
840
@@ -845,10 +846,7 @@ describe('LiveController data-model Tests', () => {
845
846
data . comment = 'server changed comment' ;
846
847
} ) ;
847
848
848
- getByText ( test . element , 'Reload' ) . click ( ) ;
849
- // wait for loading start and end
850
- await waitFor ( ( ) => expect ( test . element ) . toHaveAttribute ( 'busy' ) ) ;
851
- await waitFor ( ( ) => expect ( test . element ) . not . toHaveAttribute ( 'busy' ) ) ;
849
+ await test . component . render ( ) ;
852
850
853
851
expect ( commentField ) . toHaveValue ( 'server changed comment' ) ;
854
852
} ) ;
0 commit comments