Prueba en moca de bucle
Estoy tratando de usar el proveedor de datos en mocha para escribir menos código
var should = require('should');
var assert = require('assert');
var request = require('supertest');
var mongoose = require('mongoose');
var winston = require('winston');
var config = require('../app/config');
describe('Authentification', function() {
var url = config.web.protocol + '://' + config.web.host + ':' + config.web.port;
describe('signin',function()
{
var provider = [
{
describe: 'should return error trying to signin with empty body',
body: {},
status: 404,
message: "firstName not found"
},
{
describe: 'should return error trying to signin with no first name',
body: {
lastName: 'test',
password: 'test',
email: 'test'
},
status: 404,
message: "firstName not found"
},
{
describe: 'should return error trying to signin with no last name',
body: {
firtsName: 'test',
password: 'test',
email: 'test'
},
status: 404,
message: "lastName not found"
},
{
describe: 'should return error trying so signin with no password',
body: {
lastName: 'test',
firstName: 'test',
email: 'test'
},
status: 404,
message: "password not found"
},
{
describe: 'should return error trying so signin with no email',
body: {
lastName: 'test',
password: 'test',
firstName: 'test'
},
status: 404,
message: "email not found"
},
{
describe: 'should return error trying so signin a too long firstName',
body: {
firstName: 'kldsfjghsldkglsqkdjghqlkfjdsghldfksjghfdlskjgkldjfsdj',
lastName: 'test',
password: 'testhdksjdhfb',
email: '[email protected]'
},
status: 400,
message: "invalid firstName"
},
];
for (var i in provider) {
it(provider[i].describe, function(done) {
request(url)
.post('/user/signin')
.send(provider[i].body)
.expect(provider[i].status)
.expect(function(res)
{
assert.equal(res.body.code, provider[i].status);
assert.equal(res.body.message, provider[i].message);
})
.end(done);
});
}
});
});
Pero en este caso solo verifica la última prueba.
La salida es
Authentification
signin
✓ should return error trying to signin with empty body
✓ should return error trying to signin with no first name
✓ should return error trying to signin with no last name
✓ should return error trying so signin with no password
✓ should return error trying so signin with no email
✓ should return error trying so signin a too long firstName
6 passing (71ms)
Pero si la última prueba falla, todas las demás fallan. y si una de las otras pruebas está mal, la prueba pasa.
Quizás haya un problema asincrónico, pero no sé cómo resolverlo.