diff --git a/test/end-to-end/signin.test.js b/test/end-to-end/signin.test.js index 92bd8a060..160a66c09 100644 --- a/test/end-to-end/signin.test.js +++ b/test/end-to-end/signin.test.js @@ -771,10 +771,35 @@ describe("SuperTokens SignIn", function () { waitUntil: "domcontentloaded", }); - await submitForm(page); - let formFieldErrors = await getFieldErrors(page); - // Also standard non-optional-error is displayed if nonOptionalErrorMsg is not provided - assert.deepStrictEqual(formFieldErrors, ["Please add email", "Field is not optional"]); + let apiCallMade = false; + + const requestHandler = (request) => { + const url = request.url(); + if (url === SIGN_IN_API) { + apiCallMade = true; + request.continue(); + } else { + request.continue(); + } + }; + + await page.setRequestInterception(true); + page.on("request", requestHandler); + + try { + await submitForm(page); + let formFieldErrors = await getFieldErrors(page); + + // Also standard non-optional-error is displayed if nonOptionalErrorMsg is not provided + assert.deepStrictEqual(formFieldErrors, ["Please add email", "Field is not optional"]); + } finally { + page.off("request", requestHandler); + await page.setRequestInterception(false); + } + + if (apiCallMade) { + throw new Error("Empty form making API request to signin"); + } }); }); }); diff --git a/test/end-to-end/signup.test.js b/test/end-to-end/signup.test.js index 535e9ee14..d83c2ba1b 100644 --- a/test/end-to-end/signup.test.js +++ b/test/end-to-end/signup.test.js @@ -478,14 +478,42 @@ describe("SuperTokens SignUp", function () { }); it("Check on blank form submit nonOptionalErrorMsg gets displayed as expected", async function () { - await submitForm(page); - let formFieldErrors = await getFieldErrors(page); - // Also standard non-optional-error is displayed if nonOptionalErrorMsg is not provided - assert.deepStrictEqual(formFieldErrors, [ - "Field is not optional", - "Field is not optional", - "You must accept the terms and conditions", - ]); + let apiCallMade = false; + + const requestHandler = (request) => { + const url = request.url(); + if (url === SIGN_UP_API) { + apiCallMade = true; + request.continue(); + } else { + request.continue(); + } + }; + + await page.setRequestInterception(true); + page.on("request", requestHandler); + + // Listen for all network requests + page.on("request", (request) => {}); + + try { + // Fill and submit the form with custom fields + await submitForm(page); + let formFieldErrors = await getFieldErrors(page); + // Also standard non-optional-error is displayed if nonOptionalErrorMsg is not provided + assert.deepStrictEqual(formFieldErrors, [ + "Field is not optional", + "Field is not optional", + "You must accept the terms and conditions", + ]); + } finally { + page.off("request", requestHandler); + await page.setRequestInterception(false); + } + + if (apiCallMade) { + throw new Error("Empty form making API request to sign-up"); + } }); it("Check if nonOptionalErrorMsg overwrites server error message for non-optional fields", async function () {