我正在使用 mocha 和 chai.js 进行 CoffeeScript 单元测试。我有一个繁重的任务将咖啡文件编译到测试文件夹并启动 PhantomJS 来运行 mocha 测试。
一切正常,但是 chai.js 仅指示哪些测试失败以及预期值和实际值是什么,它没有指定测试用例中未通过的断言。有没有什么好的方法可以打印断言或至少是失败的断言的索引?然而,我也打开了chai.Assertion.includeStack
它,它只显示 JavaScript 文件中的行号,这对 CoffeeScript 测试没有太大帮助。
FizzBuzzTest.coffee
fizz = new FizzBuzz()
describe "Print numbers from 1 to 100", ->
it "First 10 digits from 1 to 5", ->
result = fizz.do()
arr = result.split(fizz.Delimiter)
expect(arr[0]).to.equal("1")
expect(arr[1]).to.equal("2")
expect(arr[2]).to.equal(fizz.Fizz)
expect(arr[3]).to.equal("3") # this assertion should fail
expect(arr[4]).to.equal(fizz.Buzz)
执行测试
$ grunt test
Running "mocha:run" (mocha) task
Testing: Content/runner.html
Print numbers from 1 to 100
✓ First 10 digits from 1 to 5
1) Last 10 digits from 95 to 100
✓ Print FizzBuzz instead of number which is divisible by both 3 and 5
✓ Check number
✓ Check Fizz
✓ Check Buzz
✓ Check FizzBuzz
✓ Check if > 100 then null
✓ Check if < 1 then null
8 passing (113ms)
1 failing
1) Print numbers from 1 to 100 Last 10 digits from 95 to 100:
AssertionError: expected true to be false
at file:///Users/milan/Sites/CoffeeTests/Content/js-libs/chai/chai.js:918
at file:///Users/milan/Sites/CoffeeTests/Content/js-libs/chai/chai.js:1159
at file:///Users/milan/Sites/CoffeeTests/Content/js-libs/chai/chai.js:3563
>> 1/9 tests failed (0.11s)
Warning: Task "mocha:run" failed. Use --force to continue.
Aborted due to warnings.
问题: 有没有一种好方法可以将 chai.js 设置为更具体地说明 AssertionError 发生的位置?
喜欢:AssertionError: 预期 true 为 false行中 expect(arr[3]).to.equal("3")
谢谢你。