Skip to content

Commit

Permalink
Add tests for incorrect default props in formFields
Browse files Browse the repository at this point in the history
  • Loading branch information
amitbadala committed Oct 30, 2023
1 parent c9df6d9 commit c305fff
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
5 changes: 2 additions & 3 deletions examples/for-tests/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ const formFields = [
label: "Your Country",
placeholder: "Where do you live?",
optional: true,
getDefaultValue: "India",
},
];

Expand Down Expand Up @@ -201,12 +200,12 @@ const incorrectFormFields = [
label: "Your Country",
placeholder: "Where do you live?",
optional: true,
getDefaultValue: () => 23,
getDefaultValue: () => 23, // return should be a string
},
{
id: "ratings",
label: "Ratings",
getDefaultValue: "best",
getDefaultValue: "best", // should be function
inputComponent: ({ value, name, onChange }) => (
<select value={value} name={name} onChange={(e) => onChange(e.target.value)} placeholder="Add Ratings">
<option value="" disabled hidden>
Expand Down
40 changes: 40 additions & 0 deletions test/end-to-end/signup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,46 @@ describe("SuperTokens SignUp", function () {
assert.strictEqual(defaultRating, updatedFields["ratings"]);
});
});

describe("Signup with Incorrect fields config", function () {
beforeEach(async function () {
// set cookie and reload which loads the form fields with incorrect field values
await page.evaluate(() => window.localStorage.setItem("SHOW_INCORRECT_FIELDS", "YES"));

await page.reload({
waitUntil: "domcontentloaded",
});
await toggleSignInSignUp(page);
});

it("Check if throws an error in console log", async function () {
// based on incorrect fields config, should get following console.error
const expectedErrors = [
"getDefaultValue for ratings must be a function",
"getDefaultValue for country must return a string",
];
const consoleErrorMessages = [];

page.on("console", async (msg) => {
// serialize the args, returns error text
const args = await Promise.all(
msg.args().map((arg) =>
arg.executionContext().evaluate((arg) => {
if (arg instanceof Error) {
return arg.message;
}
return null;
}, arg)
)
);

consoleErrorMessages = [...args.filter(Boolean(msg))];
const isSubset = expectedErrors.every((err) => consoleErrorMessages.includes(err));

assert(isSubset, "Throwing errors for incorrect field config");
});
});
});
});

describe("SuperTokens SignUp => Server Error", function () {
Expand Down

0 comments on commit c305fff

Please sign in to comment.