Test in Schleife Mokka

Ich versuche, Datenprovider in Mokka zu verwenden, um weniger Code zu schreiben

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);
            });
        }
    });
});

Aber in diesem Fall wird nur der letzte Test überprüft.

Die Ausgabe ist

  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)

Aber wenn der letzte Test fehlschlägt, schlagen alle anderen Tests fehl. und wenn einer der anderen Tests falsch ist, besteht der Test.

Es gibt vielleicht ein asynchrones Problem, aber ich weiß nicht, wie ich es lösen soll

Antworten auf die Frage(2)

Ihre Antwort auf die Frage