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

编程入门 行业动态 更新时间:2024-10-09 05:16:44

即使<a href=https://www.elefans.com/category/jswz/34/1767033.html style=进行测试也返回未定义"/>

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

我做了一个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, "");

更多推荐

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

本文发布于:2024-05-06 18:07:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1753644.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:进行测试   未定义

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!