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
];
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);
}
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
Thanks to the hint of @Lazyexpert (I've noticed you have Nan in your code, it is not the same as NaN.), I found the obvious solution...(a case sensitive issue, actualy)
try {
if (i == 0) {
expect(fields).to.be.NaN; //instead of Nan...
}