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) {
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);
//CHAI TESTING FRAMEWORK
var chai= require('chai');
var expect = require('expect').expect;
var should = require('chai').should();
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 field accepts numbers...
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)
})
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