Monday, 29 May 2017

Node.js: can't test inputs with Expect

I'm trying to test errors with Expect, but inside this try/catch block the logs aren't working. But before this block, I can see that the array is being populated by the inputs...I don't understand why the script is not entering the try/catch so the test can be made and the proper error message is returned. Any help would be apreciated. The code:

inputs = ["fname", "surname"];

for (var i = 0; i < inputs.length; i++) {
        var errors=[];
       errors.push(inputs[i]);
      console.log("FNAME"+inputs[0]+ "SURNAME" +inputs[1]); //works

         try {

            if (inputs[i] == 0) {
                expect(inputs[i]).to.be.NaN;
                expect(inputs[i]).to.have.length.above(1);
                console.log("FNAME FIELD IS " + inputs[0]); //NOT WORKING
            }

           if (inputs[i] == 1) {
                expect(inputs[i]).to.be.NaN;
                expect(inputs[i]).to.have.length.above(1);
                console.log("SURNAME FIELD IS " + inputs[1]); //not working
            }            

            return "OK";

        } catch (errors) {
            console.log("STACK" + errors(inputs[0]));
           //save(errors);
            return errors;

        }


    }



via FuManchu

No comments:

Post a Comment