@@ -197,12 +197,19 @@ test.describe("Forms", () => {
197197
198198 "app/routes/blog._index.tsx" : js `
199199 import { Form } from "react-router";
200+
201+ export function loader() {
202+ return { timestamp: Date.now() }
203+ }
204+
200205 export function action() {
201206 return { ok: true };
202207 }
203- export default function() {
208+
209+ export default function Component({ loaderData }) {
204210 return (
205211 <>
212+ <div id="timestamp">{loaderData.timestamp}</div>
206213 <Form id="${ INDEX_ROUTE_NO_ACTION } ">
207214 <input type="hidden" name="foo" defaultValue="1" />
208215 <button>Submit</button>
@@ -793,49 +800,53 @@ test.describe("Forms", () => {
793800 } ) => {
794801 let app = new PlaywrightFixture ( appFixture , page ) ;
795802
803+ const timestamp = page . locator ( `#timestamp` ) ;
804+ const form = page . locator ( `#${ INDEX_ROUTE_NO_ACTION } ` ) ;
805+ const submit = page . locator ( `#${ INDEX_ROUTE_NO_ACTION } button` ) ;
806+
796807 // Start with a query param
797808 await app . goto ( "/blog?junk=1" ) ;
798- let html = await app . getHtml ( ) ;
799- let el = getElement ( html , `#${ INDEX_ROUTE_NO_ACTION } ` ) ;
800- expect ( el . attr ( "action" ) ) . toBe ( "/blog?index&junk=1" ) ;
801- expect ( app . page . url ( ) ) . toMatch ( / \/ b l o g \? j u n k = 1 $ / ) ;
809+ const t0 = await timestamp . innerText ( ) ;
810+ await expect ( form ) . toHaveAttribute ( "action" , "/blog?index&junk=1" ) ;
811+ expect ( page . url ( ) ) . toMatch ( / \/ b l o g \? j u n k = 1 $ / ) ;
802812
803813 // On submission, we replace existing parameters (reflected in the
804814 // form action) with the values from the form data. We also do not
805815 // need to preserve the index param in the URL on GET submissions
806- await app . clickElement ( `#${ INDEX_ROUTE_NO_ACTION } button` ) ;
807- html = await app . getHtml ( ) ;
808- el = getElement ( html , `#${ INDEX_ROUTE_NO_ACTION } ` ) ;
809- expect ( el . attr ( "action" ) ) . toBe ( "/blog?index&foo=1" ) ;
810- expect ( app . page . url ( ) ) . toMatch ( / \/ b l o g \? f o o = 1 $ / ) ;
816+ await submit . click ( ) ;
817+ const t1 = await timestamp . filter ( { hasNotText : t0 } ) . innerText ( ) ;
818+ await expect ( form ) . toHaveAttribute ( "action" , "/blog?index&foo=1" ) ;
819+ expect ( page . url ( ) ) . toMatch ( / \/ b l o g \? f o o = 1 $ / ) ;
811820
812821 // Does not append duplicate params on re-submissions
813- await app . clickElement ( `#${ INDEX_ROUTE_NO_ACTION } button` ) ;
814- html = await app . getHtml ( ) ;
815- el = getElement ( html , `#${ INDEX_ROUTE_NO_ACTION } ` ) ;
816- expect ( el . attr ( "action" ) ) . toBe ( "/blog?index&foo=1" ) ;
817- expect ( app . page . url ( ) ) . toMatch ( / \/ b l o g \? f o o = 1 $ / ) ;
822+ await submit . click ( ) ;
823+ await timestamp . filter ( { hasNotText : t1 } ) . innerText ( ) ;
824+ await expect ( form ) . toHaveAttribute ( "action" , "/blog?index&foo=1" ) ;
825+ expect ( page . url ( ) ) . toMatch ( / \/ b l o g \? f o o = 1 $ / ) ;
818826 } ) ;
819827
820828 test ( "handles search params correctly on POST submissions" , async ( {
821829 page,
822830 } ) => {
823831 let app = new PlaywrightFixture ( appFixture , page ) ;
824832
833+ const timestamp = page . locator ( `#timestamp` ) ;
834+ const form = page . locator ( `#${ INDEX_ROUTE_NO_ACTION_POST } ` ) ;
835+ const submit = page . locator ( `#${ INDEX_ROUTE_NO_ACTION_POST } button` ) ;
836+
825837 // Start with a query param
826838 await app . goto ( "/blog?junk=1" ) ;
827- let html = await app . getHtml ( ) ;
828- let el = getElement ( html , `#${ INDEX_ROUTE_NO_ACTION_POST } ` ) ;
829- expect ( el . attr ( "action" ) ) . toBe ( "/blog?index&junk=1" ) ;
830- expect ( app . page . url ( ) ) . toMatch ( / \/ b l o g \? j u n k = 1 $ / ) ;
839+ const t0 = await timestamp . innerText ( ) ;
840+ await expect ( form ) . toHaveAttribute ( "action" , "/blog?index&junk=1" ) ;
841+ expect ( page . url ( ) ) . toMatch ( / \/ b l o g \? j u n k = 1 $ / ) ;
831842
832843 // Form action reflects the current params and change them on submission
833- await app . clickElement ( `# ${ INDEX_ROUTE_NO_ACTION_POST } button` ) ;
834- html = await app . getHtml ( ) ;
835- el = getElement ( html , `# ${ INDEX_ROUTE_NO_ACTION_POST } ` ) ;
836- expect ( el . attr ( "action" ) ) . toBe ( "/blog?index&junk=1" ) ;
844+ await submit . click ( ) ;
845+ await timestamp . filter ( { hasNotText : t0 } ) . innerText ( ) ;
846+ await expect ( form ) . toHaveAttribute ( "action" , "/blog?index&junk=1" ) ;
847+
837848 await page . waitForURL ( / \/ b l o g \? i n d e x & j u n k = 1 $ / ) ;
838- expect ( app . page . url ( ) ) . toMatch ( / \/ b l o g \? i n d e x & j u n k = 1 $ / ) ;
849+ expect ( page . url ( ) ) . toMatch ( / \/ b l o g \? i n d e x & j u n k = 1 $ / ) ;
839850 } ) ;
840851 } ) ;
841852
0 commit comments