diff", function() { -6ren">
gpt4 book ai didi

javascript - Jasmine 规范运行者 : Stack Trace from failed test?

转载 作者:行者123 更新时间:2023-11-29 10:48:42 27 4
gpt4 key购买 nike

我正在使用 src 文件夹中的 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 个字符才能找到答案!

关于javascript - Jasmine 规范运行者 : Stack Trace from failed test?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14359635/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com