I have these form fields I need to validate with chai expect. They all work (I get errors) except for the fields that require characters - expect(value).to.be.NaN is not working... The code:
var inputs = [response.fname, response.surname,
response.age, response.password,
response.email, response.phone,
response.city, response.country,
response.postal_code];
for (var i = 0; i < inputs.length; i++) {
var stackErrors = validate(i);
console.log(stackErrors);
}
function validate(i) {
var fields = inputs[i];
try {
if (i == 0) {
expect(fields).to.be.Nan;
}
if (i == 1) {
expect(fields).to.be.Nan;
}
if (i == 2) {
expect(fields).not.to.be.NaN;
}
if (i == 3) {
expect(fields).to.have.length.above(6);
}
if (i == 4) {
expect(fields).to.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/);
}
if (i == 5) {
expect(fields).not.to.be.NaN;
}
if (i == 6) {
expect(fields).to.be.Nan;
}
if (i == 7) {
expect(fields).to.be.Nan;
}
if (i == 8) {
expect(fields).not.to.be.NaN;
}
return "OK";
} catch (error) {
console.log(error);
return error;
}
}
})
But if test the field like in the example bellow, right after the inputs array, I get the expected assertion error...:
expect(inputs[0]).to.be.NaN;
Why is this happening? Thanks in advance
via FuManchu
No comments:
Post a Comment