Skip to content

Instantly share code, notes, and snippets.

@davilious
Created March 12, 2014 09:20
Show Gist options
  • Save davilious/9503539 to your computer and use it in GitHub Desktop.
Save davilious/9503539 to your computer and use it in GitHub Desktop.
Testing a simple toggle class show and hide with Jasmine
<a href="#" class="js-toggle-calendar">
Toggle Calendar
</a>
<div id="calendar" class="hide">
Calendar
</div>
describe "Calendar Toggle", ->
fixture.load "toggleClass_html"
it "should be a calendar", ->
expect($('#calendar')).toExist()
it "should have a hide class", ->
expect($('#calendar')).toHaveClass('hide')
it "should prevent default when fired", ->
event = {
type: 'click',
preventDefault: ->
}
spy = spyOn( event, 'preventDefault' )
$('.js-toggle-calendar').trigger(event)
expect(spy).toHaveBeenCalled()
spy.reset()
it "should toggle class hide when fired", ->
$trigger = $('.js-toggle-calendar')
$calendar = $('#calendar')
#click first time toggleClass
$trigger.trigger('click')
expect($calendar).not.toHaveClass('hide')
#click second time
$trigger.trigger('click')
expect($calendar).toHaveClass('hide')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment