Wednesday 17 May 2017

Loop over array to validate fields with Chai expect not working

I have several form fields that respond to the same validation. I'm trying to loop over them (in an array) so I can assert all of them. But I get only one element of the array checked. The code:

app.post('/process_post', urlencodedParser, function (req, res) {

   var expect = require('chai').expect, 

      fields = {
      fname:req.body.fname,
      surname:req.body.surname,
      city:req.body.city,
      country:req.body.country,
      };


//CHAI EXPECT
    var names=[fields.fname, fields.surname, fields.city, fields.country];
    console.log('ARRAY CONTENT IS ' + names);
    for(var i=0;i<names.length;i++){
        expect(names[i]).to.be.NaN;

        //console.log('EXPECT IS '+expect(names[i]).to.be.NaN);
        //console.log('NAMES LOOP ' + names[i]);
        //console.log('\n\n\n');
    }

Why isn't this working? Any ideas?



via FuManchu

No comments:

Post a Comment