Skip to content

Commit

Permalink
Add tests for incorrect usage of onChange prop
Browse files Browse the repository at this point in the history
  • Loading branch information
amitbadala committed Oct 30, 2023
1 parent c305fff commit 3f8d094
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions test/end-to-end/signup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ describe("SuperTokens SignUp", function () {
"getDefaultValue for ratings must be a function",
"getDefaultValue for country must return a string",
];
const consoleErrorMessages = [];
let consoleErrorMessages = [];

page.on("console", async (msg) => {
// serialize the args, returns error text
Expand All @@ -521,12 +521,30 @@ describe("SuperTokens SignUp", function () {
}, arg)
)
);
consoleErrorMessages.push(...args.filter(Boolean));
});

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

assert(isSubset, "Throwing errors for incorrect field config");
await page.reload({
waitUntil: "domcontentloaded",
});
await toggleSignInSignUp(page);

// Some delay so that console messages have been processed
await new Promise((resolve) => setTimeout(resolve, 1000));
let isSubset = expectedErrors.every((err) => consoleErrorMessages.includes(err));
assert(isSubset, "Throwing errors for incorrect field config - getDefaultValue prop");

// Supply NON-STRING value to onChange function should throw error
const expectedOnChangeError = ["terms value must be a string"];
// check terms and condition checkbox

let termsCheckbox = await waitForSTElement(page, '[name="terms"]');
await page.evaluate((e) => e.click(), termsCheckbox);
isSubset = false;

await new Promise((resolve) => setTimeout(resolve, 1000));
isSubset = expectedOnChangeError.every((err) => consoleErrorMessages.includes(err));
assert(isSubset, "Throwing errors for incorrect field config - onChange func.");
});
});
});
Expand Down

0 comments on commit 3f8d094

Please sign in to comment.