Skip to content

Instantly share code, notes, and snippets.

@fivetanley
Created August 8, 2012 04:34
Show Gist options
  • Save fivetanley/3292068 to your computer and use it in GitHub Desktop.
Save fivetanley/3292068 to your computer and use it in GitHub Desktop.
jasmine again
define( [ 'views/SearchView' ], function( SearchView ){
describe('SearchView', function() {
var searchView, spy
beforeEach(function() {
setFixtures( $( "<input type='search' id='search'/>" ) )
searchView = new SearchView()
searchView.render()
spy = jasmine.createSpyObj( 'event', [ 'handler' ] )
})
describe('when user is typing', function() {
it('triggers a search event the user types something', function() {
searchView.on( 'search', spy.handler )
var typeEvent = $.Event( 'textinput' )
// lowercase 't'
, keycode = 84
$( '#search' ).trigger( typeEvent )
expect( spy.handler ).toHaveBeenCalled()
})
it( 'triggers the search event with the content of the search box'
, function() {
searchView.on( 'search', spy.handler )
$( '#search' ).val( 'foo' )
var typeEvent = $.Event( 'textinput' )
// lowercase 't'
typeEvent.keycode = 84
$( '#search' ).trigger( typeEvent )
expect( spy.handler ).toHaveBeenCalledWith( 'foot' )
})
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment