我正在尝试使用我在Jasmine测试中在JS文件中定义的函数,但是当我运行测试时,它会以未定义的形式返回。
在我的规范的顶部,我需要我正在使用的咖啡文件,那么那会让我访问JS的内容吗?我可以在测试中不使用该功能吗?
employer_category.coffee
$(document).ready ->
toggle_glyphicon_plus_minus
toggle_glyphicon_plus_minus = () ->
$('#govt_category').click ->
$('#govt_category_span').toggleClass('glyphicon-plus glyphicon-minus')
$('#federal_category').click ->
$('#federal_category_span').toggleClass('glyphicon-plus glyphicon-minus')
$('#other_category').click ->
$('#other_category_span').toggleClass('glyphicon-plus glyphicon-minus')
employe_category_spec.coffee
#= require employer_category
describe 'accordion functionality', ->
beforeEach ->
employer_category = "<h5 id='govt_category'></h5>" + "<span id='govt_category_span' class='glyphicon glyphicon-plus'>"
$(employer_category).appendTo('body')
$('#govt_category').trigger('click')
it 'should invoke a click event on govt_category', ->
toggle_glyphicon_plus_minus
expect($('#govt_category_span')).toHaveClass('glyphicon-minus')