Skip to content

Commit

Permalink
Use assert instead of throw error
Browse files Browse the repository at this point in the history
  • Loading branch information
amitbadala committed Nov 16, 2023
1 parent 3907af9 commit 354a152
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 55 deletions.
21 changes: 5 additions & 16 deletions test/end-to-end/signin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -714,11 +714,8 @@ describe("SuperTokens SignIn", function () {
const postData = JSON.parse(request.postData());
expectedDefautlValues.forEach(({ id, value }) => {
let findFormData = postData.formFields.find((inputData) => inputData.id === id);
if (findFormData) {
assert.strictEqual(findFormData["value"], value, `Mismatch in payload for key: ${id}`);
} else {
throw new Error("Field not found in req.data");
}
assert.ok(findFormData, "Field not found in req.data");
assert.strictEqual(findFormData["value"], value, `Mismatch in payload for key: ${id}`);
});
interceptionPassed = true;
return request.respond({
Expand Down Expand Up @@ -748,14 +745,8 @@ describe("SuperTokens SignIn", function () {
page.off("request", requestHandler);
await page.setRequestInterception(false);
}

if (assertionError) {
throw assertionError;
}

if (!interceptionPassed) {
throw new Error("test failed");
}
assert.ok(!assertionError, assertionError?.message);
assert.ok(interceptionPassed, "Test Failed");
});
});

Expand Down Expand Up @@ -797,9 +788,7 @@ describe("SuperTokens SignIn", function () {
await page.setRequestInterception(false);
}

if (apiCallMade) {
throw new Error("Empty form making API request to signin");
}
assert.ok(!apiCallMade, "Empty form making API request to signin");
});
});
});
Expand Down
57 changes: 18 additions & 39 deletions test/end-to-end/signup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,15 +423,12 @@ describe("SuperTokens SignUp", function () {
const postData = JSON.parse(request.postData());
Object.keys(customFields).forEach((key) => {
let findFormData = postData.formFields.find((inputData) => inputData.id === key);
if (findFormData) {
assert.strictEqual(
findFormData["value"],
customFields[key],
`Mismatch in payload for key: ${key}`
);
} else {
throw new Error("Field not found in req.data");
}
assert.ok(findFormData, "Field not found in req.data");
assert.strictEqual(
findFormData["value"],
customFields[key],
`Mismatch in payload for key: ${key}`
);
});
interceptionPassed = true;
return request.respond({
Expand Down Expand Up @@ -474,13 +471,8 @@ describe("SuperTokens SignUp", function () {
await page.setRequestInterception(false);
}

if (assertionError) {
throw assertionError;
}

if (!interceptionPassed) {
throw new Error("test failed");
}
assert.ok(!assertionError, assertionError?.message);
assert.ok(interceptionPassed, "Test Failed");
});

it("Check on blank form submit nonOptionalErrorMsg gets displayed as expected", async function () {
Expand Down Expand Up @@ -514,9 +506,7 @@ describe("SuperTokens SignUp", function () {
await page.setRequestInterception(false);
}

if (apiCallMade) {
throw new Error("Empty form making API request to sign-up");
}
assert.ok(!apiCallMade, "Empty form making signup API request");
});

it("Check if nonOptionalErrorMsg overwrites server error message for non-optional fields", async function () {
Expand Down Expand Up @@ -656,11 +646,8 @@ describe("SuperTokens SignUp", function () {
const postData = JSON.parse(request.postData());
expectedDefautlValues.forEach(({ id, value }) => {
let findFormData = postData.formFields.find((inputData) => inputData.id === id);
if (findFormData) {
assert.strictEqual(findFormData["value"], value, `Mismatch in payload for key: ${id}`);
} else {
throw new Error("Field not found in req.data");
}
assert.ok(findFormData, "Field not found in req.data");
assert.strictEqual(findFormData["value"], value, `Mismatch in payload for key: ${id}`);
});
interceptionPassed = true;
return request.respond({
Expand Down Expand Up @@ -691,13 +678,8 @@ describe("SuperTokens SignUp", function () {
await page.setRequestInterception(false);
}

if (assertionError) {
throw assertionError;
}

if (!interceptionPassed) {
throw new Error("test failed");
}
assert.ok(!assertionError, assertionError?.message);
assert.ok(interceptionPassed, "Test Failed");
});
});

Expand Down Expand Up @@ -768,14 +750,11 @@ describe("SuperTokens SignUp", function () {
waitUntil: "domcontentloaded",
});

if (pageErrorMessage !== "") {
assert(
pageErrorMessage.includes(expectedErrorMessage),
`Expected "${expectedErrorMessage}" to be included in page-error`
);
} else {
throw "Empty nonOptionalErrorMsg should throw error";
}
assert.ok(pageErrorMessage !== "", "Empty nonOptionalErrorMsg should throw error");
assert(
pageErrorMessage.includes(expectedErrorMessage),
`Expected "${expectedErrorMessage}" to be included in page-error`
);
});
});
});
Expand Down

0 comments on commit 354a152

Please sign in to comment.