add site form validation tests

This commit is contained in:
realaravinth
2021-05-06 18:16:13 +05:30
parent 20ee5c35c6
commit ab3147e11d
12 changed files with 393 additions and 199 deletions

View File

@@ -23,6 +23,8 @@ import {getLoginFormHtml} from '../setUpTests';
const formClassName = 'form__box';
const formURL = '/api/v1/signin';
const noFormErr = "Can't find form";
document.body.innerHTML = getLoginFormHtml();
const form = document.querySelector('form');
@@ -37,4 +39,11 @@ it('getFromUrl workds', () => {
expect(getFormUrl(form)).toContain(formURL);
expect(getFormUrl()).toContain(formURL);
try {
document.body.innerHTML = formURL;
getFormUrl();
} catch (e) {
expect(e.message).toContain(noFormErr);
}
});

View File

@@ -33,7 +33,7 @@ const getFormUrl = (querySelector?: string | HTMLFormElement) => {
form = querySelector;
}
if (form !== undefined) {
if (form !== undefined && form !== null) {
return form.action;
} else {
throw new Error("Can't find form");