Skip to content

Commit 137b5d5

Browse files
committed
Fixing test
1 parent 02302bd commit 137b5d5

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/LiveComponent/assets/test/controller/model.test.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -810,9 +810,9 @@ describe('LiveController data-model Tests', () => {
810810
<div ${initComponent(data)}>
811811
<form data-model>
812812
<textarea name="comment" data-testid="comment">${data.comment}</textarea>
813-
</form>
813+
</form>
814814
815-
<button data-action="live#$render">Reload</button>
815+
<input data-testid="other-input">
816816
</div>
817817
`);
818818

@@ -823,17 +823,18 @@ describe('LiveController data-model Tests', () => {
823823
// delay slightly so we can type in the textarea
824824
.delayResponse(10);
825825

826-
getByText(test.element, 'Reload').click();
826+
const renderPromise = test.component.render();
827827
// mimic changing the field, but without (yet) triggering the change event
828828
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');
832830
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');
833836

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;
837838

838839
expect(commentField).toHaveValue('Live components ftw!');
839840

@@ -845,10 +846,7 @@ describe('LiveController data-model Tests', () => {
845846
data.comment = 'server changed comment';
846847
});
847848

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();
852850

853851
expect(commentField).toHaveValue('server changed comment');
854852
});

0 commit comments

Comments
 (0)