Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何检查nodejs函数的结果是否正确?_Node.js - Fatal编程技术网

Node.js 如何检查nodejs函数的结果是否正确?

Node.js 如何检查nodejs函数的结果是否正确?,node.js,Node.js,我对nodejs完全陌生 所以我用木偶演员来调用一个网页,我想检查网页上是否存在Jupyter await page.evaluate((sel) => { if (typeof Jupyter == 'undefined') { jupyterundefined = true; return; } else { Jupyter.notebook.clear_all_output(); } }, 'dummy');

我对nodejs完全陌生

所以我用木偶演员来调用一个网页,我想检查网页上是否存在Jupyter

await page.evaluate((sel) => {
    if (typeof Jupyter == 'undefined') {
        jupyterundefined = true;
        return;
    } else {
        Jupyter.notebook.clear_all_output();
    }
}, 'dummy');

await page.waitFor(60000);
if(jupyterundefined){
   //do something else
wait函数似乎没有改变jupyterundefined变量,因为它是asyn。但是我如何检查它是否与我的返回一起返回?

该函数返回一个可以保存值的
承诺,我建议您使用它

比如:

const isJupyterUndefined = await page.evaluate((sel) => {
    // === void 0 is the same as typeof undefined
    if (Jupyter === void 0) {
        return true;
    }

    Jupyter.notebook.clear_all_output();

    return false;
}, 'dummy');

await page.waitFor(60000);

if (isJupyterUndefined){
   //do something else

重新表述你的问题可能是个好主意。。。