我正在努力让Jasmine的设置和拆解方法为我工作。 我必须使用它是错误的,因为我无法在安装后让变量保持在范围内。
不起作用:
describe 'classes/model', ->
beforeEach ->
model = new Model()
describe 'the basics', ->
it 'extends Backbone.Model', ->
expect(model).toBeInstanceOf Model # Fails. 'model is not defined'
我想也许设置必须在描述的范围内。但这也行不通:
describe 'classes/model', ->
describe 'the basics', ->
beforeEach ->
model = new Model()
it 'extends Backbone.Model', ->
expect(model).toBeInstanceOf Model # Fails. 'model is not defined'
作品。 (但不使用设置方便)
describe 'classes/model', ->
describe 'the basics', ->
it 'extends Backbone.Model', ->
model = new Model()
expect(model).toBeInstanceOf Model
我做错了什么阻止beforeEach
工作?
答案 0 :(得分:4)
找到它。可能应该早点注意到:) 必须注意CoffeeScript管理变量范围的方式才能使其工作。
describe 'classes/model', ->
model = null # get it in scope
beforeEach ->
model = new Model()
describe 'the basics', ->
it 'extends Backbone.Model', ->
expect(model).toBeInstanceOf Model