Created
March 12, 2014 09:20
-
-
Save davilious/9503539 to your computer and use it in GitHub Desktop.
Testing a simple toggle class show and hide with Jasmine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a href="#" class="js-toggle-calendar"> | |
Toggle Calendar | |
</a> | |
<div id="calendar" class="hide"> | |
Calendar | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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