【发布时间】:2014-08-14 22:32:39
【问题描述】:
我正在使用beforeEach 和afterEach 钩子为测试中的每个it 块实例化一个带有模型和用户的视图。但是在第一个it 块user.attributes 的beforeEach 钩子中是空的。在第二个中,user.attributes 有一个属性,即使它是用一个空用户实例化的。为什么用属性实例化第二个用户?
describe("TestView", ->
beforeEach((done)->
@view = new TestView({model: new SomeModel(), user: new User()})
console.log(@view.user)
@view.render(done)
)
afterEach(->
@view?.remove()
)
it("should initialize and render without errors", ->
expect(@view).to.be.ok
)
it("should get the test class after being clicked", (done)->
expect($('.some-class').hasClass('test')).to.be.equal(false)
@view.$el.click()
setTimeout(->
expect($('.some-class').hasClass('test')).to.be.equal(true)
done()
, 100) # give it 100ms to let the event handlers do their things
)
)
【问题讨论】:
标签: backbone.js asynchronous mocha.js