最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

即使进行测试也返回未定义

IT培训 admin 13浏览 0评论

即使进行测试也返回未定义

我做了一个async parallel

async.parallel({
            ...,
            "dateDebut": function(cb_dateDebut) {
                request({
                            url: "/".concat(req.body.donnee)
                        }, function (error, response, body) {
                            var data = JSON.parse(body);
                            var dataJSON = data[0];
                            var dateDebut = dataJSON.Date_debut;
                            var momentDateDebut = (dateDebut == "" ? null : moment(dateDebut, "DD-MM-YYYY, H:m:s"));
                            if (momentDateDebut == null)
                                cb_dateDebut("");
                            else
                                cb_dateDebut(momentDateDebut.format("DD/MM/YYYY HH:mm"));
                });
            }
        }, function(err, results) {
            var vehicule = results.vehicule, conducteur = results.conducteur, dateDebut = results.dateDebut;
            console.log("============ dateDebut : ",dateDebut);

            sheet1.cell(9, 1).string(vehicule.vehicule_nom);
            sheet1.cell(9, 2).string(vehicule.immatriculation);
            sheet1.cell(9, 3).string(conducteur);

            var tps = moment().format('YYYYMMDHHmmss')+moment().milliseconds();
            var nom_fichier = "reporting"+tps+".xlsx";
            wb.write(path.join(__dirname, '../public/pjreporting/'+nom_fichier));

            res.send("");
        });

在运行时,我测试dateDebut何时等于""。因此,在我的测试中,results.dateDebut的期望结果应为""。但实际上我得到了undefined!那怎么了?

回答如下:首先发生错误!

更改您的代码:

// cb_dateDebut(""); cb_dateDebut(null, "");

即使进行测试也返回未定义

我做了一个async parallel

async.parallel({
            ...,
            "dateDebut": function(cb_dateDebut) {
                request({
                            url: "/".concat(req.body.donnee)
                        }, function (error, response, body) {
                            var data = JSON.parse(body);
                            var dataJSON = data[0];
                            var dateDebut = dataJSON.Date_debut;
                            var momentDateDebut = (dateDebut == "" ? null : moment(dateDebut, "DD-MM-YYYY, H:m:s"));
                            if (momentDateDebut == null)
                                cb_dateDebut("");
                            else
                                cb_dateDebut(momentDateDebut.format("DD/MM/YYYY HH:mm"));
                });
            }
        }, function(err, results) {
            var vehicule = results.vehicule, conducteur = results.conducteur, dateDebut = results.dateDebut;
            console.log("============ dateDebut : ",dateDebut);

            sheet1.cell(9, 1).string(vehicule.vehicule_nom);
            sheet1.cell(9, 2).string(vehicule.immatriculation);
            sheet1.cell(9, 3).string(conducteur);

            var tps = moment().format('YYYYMMDHHmmss')+moment().milliseconds();
            var nom_fichier = "reporting"+tps+".xlsx";
            wb.write(path.join(__dirname, '../public/pjreporting/'+nom_fichier));

            res.send("");
        });

在运行时,我测试dateDebut何时等于""。因此,在我的测试中,results.dateDebut的期望结果应为""。但实际上我得到了undefined!那怎么了?

回答如下:首先发生错误!

更改您的代码:

// cb_dateDebut(""); cb_dateDebut(null, "");

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论