Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/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 用Mocha测试噩梦EJS代码失败_Node.js_Mocha.js_Nightmare - Fatal编程技术网

Node.js 用Mocha测试噩梦EJS代码失败

Node.js 用Mocha测试噩梦EJS代码失败,node.js,mocha.js,nightmare,Node.js,Mocha.js,Nightmare,最近,我开始学习NodeJS,并编写了一个简单的Youtube scraper,它使用噩梦ejs,并返回每个视频URL的喜好、视图、作者和标题名称的数量 现在,我正尝试使用Mocha对我的代码进行单元测试(以练习一些单元测试),由于某些原因,它失败了,出现以下错误: 错误:超过2000毫秒的超时时间。确保在此测试中调用了done()回调 我试图增加超时时间(最多15秒),但没有用,我想它挂在某个地方了。我错过了什么?我也很高兴听到一些关于代码结构和实现的建设性批评 这是我的密码: var Nig

最近,我开始学习NodeJS,并编写了一个简单的Youtube scraper,它使用噩梦ejs,并返回每个视频URL的喜好、视图、作者和标题名称的数量

现在,我正尝试使用Mocha对我的代码进行单元测试(以练习一些单元测试),由于某些原因,它失败了,出现以下错误:

错误:超过2000毫秒的超时时间。确保在此测试中调用了done()回调

我试图增加超时时间(最多15秒),但没有用,我想它挂在某个地方了。我错过了什么?我也很高兴听到一些关于代码结构和实现的建设性批评

这是我的密码:

var Nightmare = require('nightmare');
var expect = require('chai').expect;
var assert = require('chai').assert;
youtube_url = 'https://www.youtube.com/watch?v=0_oPsFTyhjY';

describe('test youtube video url results', function() {
    it('should return the actual video url/title/author name/num of likes and views', function(done) {
        var nightmare = Nightmare({ show: false, gotoTimeout: 3000 })
        nightmare
            .goto(youtube_url)
            .scrollTo(10000,0)
            .wait('#comment-section-renderer-items')
            .evaluate(function (youtube_url) {
                var authorSelector = '#watch7-user-header > div > a';
                var titleSelector  = '#eow-title';
                var vcountSelector = '#watch7-views-info > div.watch-view-count';
                var lcountSelector = '#watch8-sentiment-actions > span > span:nth-child(1) > button > span';
                
                var authorElement = document.querySelector(authorSelector);
                var titleElement  = document.querySelector(titleSelector);
                var vcountElement = document.querySelector(vcountSelector);
                var lcountElement = document.querySelector(lcountSelector);

                var JSONres = {'VIDEO URL':url, 'VIDEO TITLE': titleElement.innerText,'AUTHOR NAME': authorElement.innerText,  
                'NUMBER OF VIEWS': vcountElement.innerText, 'NUMBER OF LIKES': lcountElement.innerText};

                return (JSONres)
            },youtube_url)
            .end()
            .then(function (result) {
                try{
                    expect(result['VIDEO URL']).to.equal(youtube_url);
                    expect(result['VIDEO TITLE']).to.equal('The Best Mouse in the World?');
                    expect(result['AUTHOR NAME']).to.equal('Unbox Therapy');
                    assert.isAtLeast(result['NUMBER OF VIEWS'], 1816808, 'The number of views is at least the number of views that has been already seen');
                    // It's possible to remove your like from the video so hypothetically many users may remove their likes thus there is no upper/lower
                    // bound on the like amount a video can have at any time except that it must be non-negative.
                    assert.isAtLeast(result['NUMBER OF LIKES'], 0, 'The number of likes is at least a non-negative number');
                    done();
                }
                catch(error){
                    done(error);
                }
            })

    });
});

意外地将超时时间提高到20秒[使用
此.timeout(20000);
]刚刚解决了问题(出于某种原因),尽管测试实际花费的时间从未超过6秒

您可能需要使用此。超时(0);禁用超时