【发布时间】:2014-12-10 00:40:47
【问题描述】:
我开始使用 Protractor,我尝试做的第一件事是使用 Mocha 和 Chai 而不是 Jasmine。虽然现在我不确定这是否是个好主意。
首先我需要让 Chai 可以从所有规范文件中访问,而不必每次都导入,我发现可以在 protractor.conf 文件中进行:
onPrepare: ->
global.chai = require 'chai'
chai.use require 'chai-string'
chai.use require 'chai-as-promised'
global.expect = chai.expect
现在在这样的规范中:
it "when clicked should sort ",->
headerColumns.get(0).click()
firstCellText = $$(".first-cell").getText()
secondCellText = $$(".second-cell").getText()
# this won't work
expect(firstCellText).eventually.be.above(secondCellText)
为了让它发挥作用,我可以做到:
# now this works
$$(".second-cell").getText().then (secondCellText)->
expect(firstCellText).eventually.be.above(secondCellText)
但这很丑陋,我不想一直在.then 内包装东西。我在想应该有更好的方法(?)
【问题讨论】:
标签: jasmine mocha.js protractor chai chai-as-promised