Wednesday, 17 May 2017

Chai Testing: assertionError: expected '942253' to be a number

I'm testing form fields with Chai Framework, but so far, only this one works:

response.age.should.be.within(5,120);

If I input a character or a number bellow 5 or above 120, i get the correct error:

AssertionError: expected 'qqq' to be within 5..120

or

AssertionError: expected '1' to be within 5..120

The entire code is:

var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var http = require('http');

var urlencodedParser = bodyParser.urlencoded({ extended: false })

app.use(express.static('public'));

app.get('/index.html', function (req, res) {
   res.sendFile( __dirname + "/" + "index.html" );

})

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



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

  response = {
  fname:req.body.fname,
  surname:req.body.surname,
  age:req.body.age,
  phone:req.body.phone,
  city:req.body.phone,
  email:req.body.email,
  country:req.body.country,
  postal_code:req.body.postal_code,
  password:req.body.password

};
   console.log(response);

response.phone.should.be.a('number');
response.fname.should.be.a('string');


})

// SERVER 

       var server = app.listen(8081, function () {
       var host = server.address().address
       var port = server.address().port

       console.log("Listening at http://%s:%s", host, port)
    })

For the field bellow, if I input a number:

response.phone.should.be.a('number');

I get this on the console:

AssertionError: expected '942253' to be a number

And also this one bellow accepts numbers...

response.fname.should.be.a('string');

I don't get it, I've followed the instructions on the documentation, and I've searched for solutions, but none of them seemed to work...Can someone tell me what I'm doing wrong? Thanks



via glassraven

No comments:

Post a Comment