From 20b04c9bf20bdd9be4e57ce7a1b9e0033b2ea325 Mon Sep 17 00:00:00 2001 From: Will Daly Date: Wed, 6 Mar 2013 13:06:15 -0500 Subject: [PATCH] Fixed broken calculator test in lms coffee scripts --- lms/static/coffee/spec/calculator_spec.coffee | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lms/static/coffee/spec/calculator_spec.coffee b/lms/static/coffee/spec/calculator_spec.coffee index 072d220a44..a8210ce68b 100644 --- a/lms/static/coffee/spec/calculator_spec.coffee +++ b/lms/static/coffee/spec/calculator_spec.coffee @@ -31,12 +31,19 @@ describe 'Calculator', -> $('form#calculator').submit() describe 'toggle', -> - it 'toggle the calculator and focus the input', -> - spyOn $.fn, 'focus' - @calculator.toggle(jQuery.Event("click")) + it 'focuses the input when toggled', -> - expect($('li.calc-main')).toHaveClass('open') - expect($('#calculator_wrapper #calculator_input').focus).toHaveBeenCalled() + # Since the focus is called asynchronously, we need to + # wait until focus() is called. + didFocus = false + runs -> + spyOn($.fn, 'focus').andCallFake (elementName) -> didFocus = true + @calculator.toggle(jQuery.Event("click")) + + waitsFor (-> didFocus), "focus() should have been called on the input", 1000 + + runs -> + expect($('#calculator_wrapper #calculator_input').focus).toHaveBeenCalled() it 'toggle the close button on the calculator button', -> @calculator.toggle(jQuery.Event("click"))