Jasmine Spec Runner:失败测试的堆栈跟踪
Jasmine Spec Runner: Stack Trace from failed test?
我正在用src-folder中的moment.js做一个Jasmine-standalone-demo。
describe("moment.js -> diff", function() {
var start, end;
it("leap year", function() {
start = moment([2012, 1, 26]);
end = moment([2012, 2, 4]);
expect( end.diff(start, "days") ).toEqual(7);
});
it("winter-/summertime", function() {
start = moment("2012-10-28T02:00:00+02:00");
end = moment("2012-10-28T03:00:00+01:00");
expect( end.diff(start, "hours") ).toEqual(0);
});
});
第二个测试预计会失败,它确实失败了(diff返回1),但是Jasmine给出了一个堆栈跟踪,这对我来说似乎没什么用,除非Jasmine本身有一个错误:
Error: Expected 1 to equal 0.
at new jasmine.ExpectationResult (http://localhost/jasmine/lib/jasmine-1.3.1/jasmine.js:114:32)
at null.toEqual (http://localhost/jasmine/lib/jasmine-1.3.1/jasmine.js:1235:29)
at null.<anonymous> (http://localhost/jasmine/spec/MomentSpec.js:11:38)
at jasmine.Block.execute (http://localhost/jasmine/lib/jasmine-1.3.1/jasmine.js:1064:17)
at jasmine.Queue.next_ (http://localhost/jasmine/lib/jasmine-1.3.1/jasmine.js:2096:31)
at jasmine.Queue.start (http://localhost/jasmine/lib/jasmine-1.3.1/jasmine.js:2049:8)
at jasmine.Spec.execute (http://localhost/jasmine/lib/jasmine-1.3.1/jasmine.js:2376:14)
at jasmine.Queue.next_ (http://localhost/jasmine/lib/jasmine-1.3.1/jasmine.js:2096:31)
at onComplete (http://localhost/jasmine/lib/jasmine-1.3.1/jasmine.js:2092:18)
at jasmine.Spec.finish (http://localhost/jasmine/lib/jasmine-1.3.1/jasmine.js:2350:5)
谁能指点一下单元测试新手。也许我做错了什么。
如果在it()
块中有许多expect()
,堆栈跟踪将告诉您哪个expect()
函数失败。
正如@zbynour所提到的,您必须去MomentSpec.js
中的第11行,第38个字符才能找到答案!
相关文章:
- Fresh Spark Install+Homestead上的Vue异步堆栈跟踪错误
- 打印javascript控制台的堆栈跟踪
- 如何在Chrome扩展内容脚本中获取错误堆栈跟踪
- 正在获取控制台消息的堆栈跟踪
- Bluebird 在与 Sequelize/MySQL 一起使用时显示损坏的堆栈跟踪
- 如何在Internet Explorer中获取javascript堆栈跟踪.e.stack 返回 “Undefined”
- JavaScript 中的 try-catch:如何获取原始错误的堆栈跟踪或行号
- 节点错误堆栈跟踪未定义
- 如何在 node.js 中输出深度堆栈跟踪
- 如何在 Firefox 中获取 JavaScript 堆栈跟踪
- 蓝鸟(或其他承诺库)保持承诺错误堆栈跟踪
- 在 Karma (AngularJS) 中抑制堆栈跟踪
- Firebug:角度堆栈跟踪不显示错误的来源(行号,文件)
- 在node.js中获取*current*堆栈跟踪(例如,通过SIGINT)
- 在开发Firefox扩展时获取堆栈跟踪
- 正在清理Protractor堆栈跟踪
- 从nodejs中抛出的字符串中获取堆栈跟踪
- 有没有一种方法可以从Internet Explorer中的Error对象中获取行号或堆栈跟踪
- 何时在窗口上提供正确的堆栈跟踪.错误函数
- 如何将js堆栈跟踪替换为include"行“;以及“;位置“;文本