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

问题描述 投票:0回答:1

我做了一个async parallel

async.parallel({
            ...,
            "dateDebut": function(cb_dateDebut) {
                request({
                            url: "https://alfred.telma.net/track_/trackable/dateDebut/".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!那怎么了?

node.js async.js
1个回答
1
投票
首先发生错误!

更改您的代码:

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

© www.soinside.com 2019 - 2024. All rights reserved.