Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.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
Javascript 用摩卡测试余烬js?_Javascript_Ember.js_Mocha.js - Fatal编程技术网

Javascript 用摩卡测试余烬js?

Javascript 用摩卡测试余烬js?,javascript,ember.js,mocha.js,Javascript,Ember.js,Mocha.js,我正在使用lineman和testem、ember以及mocha+chai 我想测试ember。到目前为止,由于测试脚本和测试页面的处理方式,我可以访问页面并测试其内容 测试页面看起来像 ------------------------ Loop through mocha test cases ------------------------ Ember App View ------------------------ 但是,当我尝试测试页面标题等内容之外的内容时: descr

我正在使用
lineman
testem
ember
以及
mocha+chai

我想测试
ember
。到目前为止,由于测试脚本和测试页面的处理方式,我可以访问页面并测试其内容

测试页面看起来像

------------------------
Loop through mocha test cases

------------------------

Ember App View




------------------------
但是,当我尝试测试页面标题等内容之外的内容时:

describe('testing page title', function () {
    it('should equal ember-template', function () {
        visit('/');
        find('title').text().should.equal('ember-template');
        find('title').length; // this is 0
    });
});
这给了我一个错误

✘ expected '' to equal 'ember-template'
    AssertionError: expected '' to equal 'ember-template'
如何使用
mocha
完全测试
ember

visit()
是异步的,而
find()
是同步的(这只是引擎盖下的一个jquery选择),因此在检查标题时,到页面的转换可能还没有完成。
andThen()
测试助手将在执行回调之前等待前面的异步活动完成。请尝试以下操作:

describe('testing page title', function () {
    it('should equal ember-template', function () {
        visit('/');
        andThen(function() {
            find('title').text().should.equal('ember-template');
            find('title').length; // this is 0
        });
    });
});

在我看来,根页面似乎没有标题,或者您试图在页面完全打开之前获取它loaded@c0d3junk13我肯定这一页有标题,但你的第二个假设似乎有道理。我不确定
ember
测试是如何工作的,所以我不知道
visit
find
是否执行
async
。嗯。。。尝试了这个,得到了同样的错误<代码>断言错误:如果导航到“/”并在控制台中输入
$('title')。text()
是否返回“余烬模板”,请澄清?我不确定这是否是有效的jquery,这可以解释为什么上述操作失败。假设您试图获取窗口标题,我认为有效的jquery应该是
$(document.attr('title')
。另外,我刚刚注意到
find()
帮助程序的作用域特别限定在应用程序的根元素上,因此如果标题不在该范围内,则需要使用jQuery来选择它,并对其运行断言,而不是对余烬帮助程序运行断言。是的,
$('title')。text()
确实返回'Ember template'。好的,因为
find()
helper的作用域是应用程序的根元素(如果我理解正确,“title”在该作用域之外),如果将断言更改为
$(“title”).text().should.equal('ember-template'),会发生什么情况?不确定有什么好办法可以解决这个问题,因为Testem会更改页面标题,并且没有任何选项可以让它不这样做。如果这是一个重要的测试,听起来你需要使用Testem以外的东西。